diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-11-28 12:38:53 -0800 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-11-28 13:17:33 -0800 |
| commit | fc06114ddfd2bcdbc4f29076c226a7a1d66ea8d6 (patch) | |
| tree | bd9de2c450f23b8ff0e09130ab59d784ace5b5e3 /src/libsyntax | |
| parent | 669fbddc4435a9ab152332df06a7fcca789c8059 (diff) | |
| parent | 8179e268efd86ae5c1bcf21b4f8d4e01eea7c193 (diff) | |
| download | rust-fc06114ddfd2bcdbc4f29076c226a7a1d66ea8d6.tar.gz rust-fc06114ddfd2bcdbc4f29076c226a7a1d66ea8d6.zip | |
Merge remote-tracking branch 'brson/companion' into incoming
Conflicts: src/compiletest/compiletest.rs src/libcargo/cargo.rs src/libcore/core.rs src/librustc/rustc.rs src/librustdoc/rustdoc.rc
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 657 | ||||
| -rw-r--r-- | src/libsyntax/ast_map.rs | 23 | ||||
| -rw-r--r-- | src/libsyntax/attr.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/codemap.rs | 46 | ||||
| -rw-r--r-- | src/libsyntax/diagnostic.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/mod.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/proto.rs | 15 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 27 | ||||
| -rw-r--r-- | src/libsyntax/parse.rs | 57 | ||||
| -rw-r--r-- | src/libsyntax/parse/comments.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax/parse/eval.rs | 21 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 28 | ||||
| -rw-r--r-- | src/libsyntax/parse/obsolete.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 178 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 285 | ||||
| -rw-r--r-- | src/libsyntax/print/pp.rs | 15 | ||||
| -rw-r--r-- | src/libsyntax/syntax.rc | 83 | ||||
| -rw-r--r-- | src/libsyntax/visit.rs | 10 |
18 files changed, 188 insertions, 1313 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index d09dd6f7bd1..1adcadf1b6a 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -50,15 +50,7 @@ impl<D: Deserializer> ident: Deserializable<D> { } impl ident: cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &ident) -> bool { self.repr == other.repr } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &ident) -> bool { (*self).repr == other.repr } - #[cfg(stage0)] - pure fn ne(other: &ident) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &ident) -> bool { !(*self).eq(other) } } @@ -97,19 +89,9 @@ type node_id = int; type def_id = {crate: crate_num, node: node_id}; impl def_id : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &def_id) -> bool { - self.crate == (*other).crate && self.node == (*other).node - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &def_id) -> bool { (*self).crate == (*other).crate && (*self).node == (*other).node } - #[cfg(stage0)] - pure fn ne(other: &def_id) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &def_id) -> bool { !(*self).eq(other) } } @@ -158,129 +140,6 @@ enum def { } impl def : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &def) -> bool { - match self { - def_fn(e0a, e1a) => { - match (*other) { - def_fn(e0b, e1b) => e0a == e0b && e1a == e1b, - _ => false - } - } - def_static_method(e0a, e1a, e2a) => { - match (*other) { - def_static_method(e0b, e1b, e2b) => - e0a == e0b && e1a == e1b && e2a == e2b, - _ => false - } - } - def_self(e0a) => { - match (*other) { - def_self(e0b) => e0a == e0b, - _ => false - } - } - def_mod(e0a) => { - match (*other) { - def_mod(e0b) => e0a == e0b, - _ => false - } - } - def_foreign_mod(e0a) => { - match (*other) { - def_foreign_mod(e0b) => e0a == e0b, - _ => false - } - } - def_const(e0a) => { - match (*other) { - def_const(e0b) => e0a == e0b, - _ => false - } - } - def_arg(e0a, e1a) => { - match (*other) { - def_arg(e0b, e1b) => e0a == e0b && e1a == e1b, - _ => false - } - } - def_local(e0a, e1a) => { - match (*other) { - def_local(e0b, e1b) => e0a == e0b && e1a == e1b, - _ => false - } - } - def_variant(e0a, e1a) => { - match (*other) { - def_variant(e0b, e1b) => e0a == e0b && e1a == e1b, - _ => false - } - } - def_ty(e0a) => { - match (*other) { - def_ty(e0b) => e0a == e0b, - _ => false - } - } - def_prim_ty(e0a) => { - match (*other) { - def_prim_ty(e0b) => e0a == e0b, - _ => false - } - } - def_ty_param(e0a, e1a) => { - match (*other) { - def_ty_param(e0b, e1b) => e0a == e0b && e1a == e1b, - _ => false - } - } - def_binding(e0a, e1a) => { - match (*other) { - def_binding(e0b, e1b) => e0a == e0b && e1a == e1b, - _ => false - } - } - def_use(e0a) => { - match (*other) { - def_use(e0b) => e0a == e0b, - _ => false - } - } - def_upvar(e0a, e1a, e2a, e3a) => { - match (*other) { - def_upvar(e0b, e1b, e2b, e3b) => - e0a == e0b && e1a == e1b && e2a == e2b && e3a == e3b, - _ => false - } - } - def_class(e0a) => { - match (*other) { - def_class(e0b) => e0a == e0b, - _ => false - } - } - def_typaram_binder(e0a) => { - match (*other) { - def_typaram_binder(e1a) => e0a == e1a, - _ => false - } - } - def_region(e0a) => { - match (*other) { - def_region(e0b) => e0a == e0b, - _ => false - } - } - def_label(e0a) => { - match (*other) { - def_label(e0b) => e0a == e0b, - _ => false - } - } - } - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &def) -> bool { match (*self) { def_fn(e0a, e1a) => { @@ -401,10 +260,6 @@ impl def : cmp::Eq { } } } - #[cfg(stage0)] - pure fn ne(other: &def) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &def) -> bool { !(*self).eq(other) } } @@ -415,25 +270,10 @@ type crate_cfg = ~[@meta_item]; type crate = spanned<crate_>; type crate_ = - {directives: ~[@crate_directive], - module: _mod, + {module: _mod, attrs: ~[attribute], config: crate_cfg}; -enum crate_directive_ { - cdir_src_mod(visibility, ident, ~[attribute]), - cdir_dir_mod(visibility, ident, ~[@crate_directive], ~[attribute]), - - // NB: cdir_view_item is *not* processed by the rest of the compiler, the - // attached view_items are sunk into the crate's module during parsing, - // and processed (resolved, imported, etc.) there. This enum-variant - // exists only to preserve the view items in order in case we decide to - // pretty-print crates in the future. - cdir_view_item(@view_item), -} - -type crate_directive = spanned<crate_directive_>; - type meta_item = spanned<meta_item_>; #[auto_serialize] @@ -507,37 +347,6 @@ impl binding_mode : to_bytes::IterBytes { } impl binding_mode : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &binding_mode) -> bool { - match self { - bind_by_value => { - match (*other) { - bind_by_value => true, - _ => false - } - } - bind_by_move => { - match (*other) { - bind_by_move => true, - _ => false - } - } - bind_by_ref(e0a) => { - match (*other) { - bind_by_ref(e0b) => e0a == e0b, - _ => false - } - } - bind_by_implicit_ref => { - match (*other) { - bind_by_implicit_ref => true, - _ => false - } - } - } - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &binding_mode) -> bool { match (*self) { bind_by_value => { @@ -566,10 +375,6 @@ impl binding_mode : cmp::Eq { } } } - #[cfg(stage0)] - pure fn ne(other: &binding_mode) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &binding_mode) -> bool { !(*self).eq(other) } } @@ -617,19 +422,9 @@ impl mutability : to_bytes::IterBytes { } impl mutability : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &mutability) -> bool { - (self as uint) == ((*other) as uint) - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &mutability) -> bool { ((*self) as uint) == ((*other) as uint) } - #[cfg(stage0)] - pure fn ne(other: &mutability) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &mutability) -> bool { !(*self).eq(other) } } @@ -643,19 +438,9 @@ pub enum Proto { } impl Proto : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &Proto) -> bool { - (self as uint) == ((*other) as uint) - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &Proto) -> bool { ((*self) as uint) == ((*other) as uint) } - #[cfg(stage0)] - pure fn ne(other: &Proto) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &Proto) -> bool { !(*self).eq(other) } } @@ -726,19 +511,9 @@ enum binop { } impl binop : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &binop) -> bool { - (self as uint) == ((*other) as uint) - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &binop) -> bool { ((*self) as uint) == ((*other) as uint) } - #[cfg(stage0)] - pure fn ne(other: &binop) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &binop) -> bool { !(*self).eq(other) } } @@ -753,43 +528,6 @@ enum unop { } impl unop : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &unop) -> bool { - match self { - box(e0a) => { - match (*other) { - box(e0b) => e0a == e0b, - _ => false - } - } - uniq(e0a) => { - match (*other) { - uniq(e0b) => e0a == e0b, - _ => false - } - } - deref => { - match (*other) { - deref => true, - _ => false - } - } - not => { - match (*other) { - not => true, - _ => false - } - } - neg => { - match (*other) { - neg => true, - _ => false - } - } - } - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &unop) -> bool { match (*self) { box(e0a) => { @@ -824,12 +562,6 @@ impl unop : cmp::Eq { } } } - #[cfg(stage0)] - pure fn ne(other: &unop) -> bool { - !self.eq(other) - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &unop) -> bool { !(*self).eq(other) } @@ -872,25 +604,6 @@ impl<T: to_bytes::IterBytes> inferable<T> : to_bytes::IterBytes { } impl<T:cmp::Eq> inferable<T> : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &inferable<T>) -> bool { - match self { - expl(e0a) => { - match (*other) { - expl(e0b) => e0a == e0b, - _ => false - } - } - infer(e0a) => { - match (*other) { - infer(e0b) => e0a == e0b, - _ => false - } - } - } - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &inferable<T>) -> bool { match (*self) { expl(e0a) => { @@ -907,10 +620,6 @@ impl<T:cmp::Eq> inferable<T> : cmp::Eq { } } } - #[cfg(stage0)] - pure fn ne(other: &inferable<T>) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &inferable<T>) -> bool { !(*self).eq(other) } } @@ -935,19 +644,9 @@ impl rmode : to_bytes::IterBytes { impl rmode : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &rmode) -> bool { - (self as uint) == ((*other) as uint) - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &rmode) -> bool { ((*self) as uint) == ((*other) as uint) } - #[cfg(stage0)] - pure fn ne(other: &rmode) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &rmode) -> bool { !(*self).eq(other) } } @@ -998,17 +697,6 @@ type field = spanned<field_>; enum blk_check_mode { default_blk, unsafe_blk, } impl blk_check_mode : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &blk_check_mode) -> bool { - match (self, (*other)) { - (default_blk, default_blk) => true, - (unsafe_blk, unsafe_blk) => true, - (default_blk, _) => false, - (unsafe_blk, _) => false, - } - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &blk_check_mode) -> bool { match ((*self), (*other)) { (default_blk, default_blk) => true, @@ -1017,10 +705,6 @@ impl blk_check_mode : cmp::Eq { (unsafe_blk, _) => false, } } - #[cfg(stage0)] - pure fn ne(other: &blk_check_mode) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &blk_check_mode) -> bool { !(*self).eq(other) } } @@ -1237,35 +921,6 @@ enum lit_ { } impl ast::lit_: cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &ast::lit_) -> bool { - match (self, *other) { - (lit_str(a), lit_str(b)) => a == b, - (lit_int(val_a, ty_a), lit_int(val_b, ty_b)) => { - val_a == val_b && ty_a == ty_b - } - (lit_uint(val_a, ty_a), lit_uint(val_b, ty_b)) => { - val_a == val_b && ty_a == ty_b - } - (lit_int_unsuffixed(a), lit_int_unsuffixed(b)) => a == b, - (lit_float(val_a, ty_a), lit_float(val_b, ty_b)) => { - val_a == val_b && ty_a == ty_b - } - (lit_float_unsuffixed(a), lit_float_unsuffixed(b)) => a == b, - (lit_nil, lit_nil) => true, - (lit_bool(a), lit_bool(b)) => a == b, - (lit_str(_), _) => false, - (lit_int(*), _) => false, - (lit_uint(*), _) => false, - (lit_int_unsuffixed(*), _) => false, - (lit_float(*), _) => false, - (lit_float_unsuffixed(*), _) => false, - (lit_nil, _) => false, - (lit_bool(_), _) => false - } - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &ast::lit_) -> bool { match ((*self), *other) { (lit_str(a), lit_str(b)) => a == b, @@ -1292,10 +947,6 @@ impl ast::lit_: cmp::Eq { (lit_bool(_), _) => false } } - #[cfg(stage0)] - pure fn ne(other: &ast::lit_) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &ast::lit_) -> bool { !(*self).eq(other) } } @@ -1346,25 +997,6 @@ impl int_ty : to_bytes::IterBytes { } impl int_ty : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &int_ty) -> bool { - match (self, (*other)) { - (ty_i, ty_i) => true, - (ty_char, ty_char) => true, - (ty_i8, ty_i8) => true, - (ty_i16, ty_i16) => true, - (ty_i32, ty_i32) => true, - (ty_i64, ty_i64) => true, - (ty_i, _) => false, - (ty_char, _) => false, - (ty_i8, _) => false, - (ty_i16, _) => false, - (ty_i32, _) => false, - (ty_i64, _) => false, - } - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &int_ty) -> bool { match ((*self), (*other)) { (ty_i, ty_i) => true, @@ -1381,10 +1013,6 @@ impl int_ty : cmp::Eq { (ty_i64, _) => false, } } - #[cfg(stage0)] - pure fn ne(other: &int_ty) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &int_ty) -> bool { !(*self).eq(other) } } @@ -1407,23 +1035,6 @@ impl uint_ty : to_bytes::IterBytes { } impl uint_ty : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &uint_ty) -> bool { - match (self, (*other)) { - (ty_u, ty_u) => true, - (ty_u8, ty_u8) => true, - (ty_u16, ty_u16) => true, - (ty_u32, ty_u32) => true, - (ty_u64, ty_u64) => true, - (ty_u, _) => false, - (ty_u8, _) => false, - (ty_u16, _) => false, - (ty_u32, _) => false, - (ty_u64, _) => false - } - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &uint_ty) -> bool { match ((*self), (*other)) { (ty_u, ty_u) => true, @@ -1438,10 +1049,6 @@ impl uint_ty : cmp::Eq { (ty_u64, _) => false } } - #[cfg(stage0)] - pure fn ne(other: &uint_ty) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &uint_ty) -> bool { !(*self).eq(other) } } @@ -1464,25 +1071,12 @@ impl float_ty : to_bytes::IterBytes { } impl float_ty : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &float_ty) -> bool { - match (self, (*other)) { - (ty_f, ty_f) | (ty_f32, ty_f32) | (ty_f64, ty_f64) => true, - (ty_f, _) | (ty_f32, _) | (ty_f64, _) => false - } - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &float_ty) -> bool { match ((*self), (*other)) { (ty_f, ty_f) | (ty_f32, ty_f32) | (ty_f64, ty_f64) => true, (ty_f, _) | (ty_f32, _) | (ty_f64, _) => false } } - #[cfg(stage0)] - pure fn ne(other: &float_ty) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &float_ty) -> bool { !(*self).eq(other) } } @@ -1502,43 +1096,6 @@ enum prim_ty { } impl prim_ty : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &prim_ty) -> bool { - match self { - ty_int(e0a) => { - match (*other) { - ty_int(e0b) => e0a == e0b, - _ => false - } - } - ty_uint(e0a) => { - match (*other) { - ty_uint(e0b) => e0a == e0b, - _ => false - } - } - ty_float(e0a) => { - match (*other) { - ty_float(e0b) => e0a == e0b, - _ => false - } - } - ty_str => { - match (*other) { - ty_str => true, - _ => false - } - } - ty_bool => { - match (*other) { - ty_bool => true, - _ => false - } - } - } - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &prim_ty) -> bool { match (*self) { ty_int(e0a) => { @@ -1573,10 +1130,6 @@ impl prim_ty : cmp::Eq { } } } - #[cfg(stage0)] - pure fn ne(other: &prim_ty) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &prim_ty) -> bool { !(*self).eq(other) } } @@ -1601,27 +1154,12 @@ enum Onceness { } impl Onceness : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &Onceness) -> bool { - match (self, *other) { - (Once, Once) | (Many, Many) => true, - _ => false - } - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &Onceness) -> bool { match ((*self), *other) { (Once, Once) | (Many, Many) => true, _ => false } } - #[cfg(stage0)] - pure fn ne(other: &Onceness) -> bool { - !self.eq(other) - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &Onceness) -> bool { !(*self).eq(other) } @@ -1663,21 +1201,9 @@ enum ty_ { // Equality and byte-iter (hashing) can be quite approximate for AST types. // since we only care about this for normalizing them to "real" types. impl Ty : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &Ty) -> bool { - ptr::addr_of(&self) == ptr::addr_of(&(*other)) - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &Ty) -> bool { ptr::addr_of(&(*self)) == ptr::addr_of(&(*other)) } - #[cfg(stage0)] - pure fn ne(other: &Ty) -> bool { - ptr::addr_of(&self) != ptr::addr_of(&(*other)) - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &Ty) -> bool { ptr::addr_of(&(*self)) != ptr::addr_of(&(*other)) } @@ -1735,19 +1261,9 @@ impl purity : to_bytes::IterBytes { } impl purity : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &purity) -> bool { - (self as uint) == ((*other) as uint) - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &purity) -> bool { ((*self) as uint) == ((*other) as uint) } - #[cfg(stage0)] - pure fn ne(other: &purity) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &purity) -> bool { !(*self).eq(other) } } @@ -1774,17 +1290,6 @@ impl ret_style : to_bytes::IterBytes { } impl ret_style : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &ret_style) -> bool { - match (self, (*other)) { - (noreturn, noreturn) => true, - (return_val, return_val) => true, - (noreturn, _) => false, - (return_val, _) => false, - } - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &ret_style) -> bool { match ((*self), (*other)) { (noreturn, noreturn) => true, @@ -1793,10 +1298,6 @@ impl ret_style : cmp::Eq { (return_val, _) => false, } } - #[cfg(stage0)] - pure fn ne(other: &ret_style) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &ret_style) -> bool { !(*self).eq(other) } } @@ -1812,49 +1313,6 @@ enum self_ty_ { } impl self_ty_ : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &self_ty_) -> bool { - match self { - sty_static => { - match (*other) { - sty_static => true, - _ => false - } - } - sty_by_ref => { - match (*other) { - sty_by_ref => true, - _ => false - } - } - sty_value => { - match (*other) { - sty_value => true, - _ => false - } - } - sty_region(e0a) => { - match (*other) { - sty_region(e0b) => e0a == e0b, - _ => false - } - } - sty_box(e0a) => { - match (*other) { - sty_box(e0b) => e0a == e0b, - _ => false - } - } - sty_uniq(e0a) => { - match (*other) { - sty_uniq(e0b) => e0a == e0b, - _ => false - } - } - } - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &self_ty_) -> bool { match (*self) { sty_static => { @@ -1895,10 +1353,6 @@ impl self_ty_ : cmp::Eq { } } } - #[cfg(stage0)] - pure fn ne(other: &self_ty_) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &self_ty_) -> bool { !(*self).eq(other) } } @@ -1930,36 +1384,13 @@ enum foreign_abi { enum foreign_mod_sort { named, anonymous } impl foreign_mod_sort : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &foreign_mod_sort) -> bool { - (self as uint) == ((*other) as uint) - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &foreign_mod_sort) -> bool { ((*self) as uint) == ((*other) as uint) } - #[cfg(stage0)] - pure fn ne(other: &foreign_mod_sort) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &foreign_mod_sort) -> bool { !(*self).eq(other) } } impl foreign_abi : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &foreign_abi) -> bool { - match (self, (*other)) { - (foreign_abi_rust_intrinsic, foreign_abi_rust_intrinsic) => true, - (foreign_abi_cdecl, foreign_abi_cdecl) => true, - (foreign_abi_stdcall, foreign_abi_stdcall) => true, - (foreign_abi_rust_intrinsic, _) => false, - (foreign_abi_cdecl, _) => false, - (foreign_abi_stdcall, _) => false, - } - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &foreign_abi) -> bool { match ((*self), (*other)) { (foreign_abi_rust_intrinsic, foreign_abi_rust_intrinsic) => true, @@ -1970,10 +1401,6 @@ impl foreign_abi : cmp::Eq { (foreign_abi_stdcall, _) => false, } } - #[cfg(stage0)] - pure fn ne(other: &foreign_abi) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &foreign_abi) -> bool { !(*self).eq(other) } } @@ -2023,19 +1450,9 @@ type path_list_ident = spanned<path_list_ident_>; enum namespace { module_ns, type_value_ns } impl namespace : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &namespace) -> bool { - (self as uint) == ((*other) as uint) - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &namespace) -> bool { ((*self) as uint) == ((*other) as uint) } - #[cfg(stage0)] - pure fn ne(other: &namespace) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &namespace) -> bool { !(*self).eq(other) } } @@ -2083,19 +1500,9 @@ type attribute = spanned<attribute_>; enum attr_style { attr_outer, attr_inner, } impl attr_style : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &attr_style) -> bool { - (self as uint) == ((*other) as uint) - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &attr_style) -> bool { ((*self) as uint) == ((*other) as uint) } - #[cfg(stage0)] - pure fn ne(other: &attr_style) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &attr_style) -> bool { !(*self).eq(other) } } @@ -2122,19 +1529,6 @@ type trait_ref = {path: @path, ref_id: node_id, impl_id: node_id}; enum visibility { public, private, inherited } impl visibility : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &visibility) -> bool { - match (self, (*other)) { - (public, public) => true, - (private, private) => true, - (inherited, inherited) => true, - (public, _) => false, - (private, _) => false, - (inherited, _) => false, - } - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &visibility) -> bool { match ((*self), (*other)) { (public, public) => true, @@ -2145,10 +1539,6 @@ impl visibility : cmp::Eq { (inherited, _) => false, } } - #[cfg(stage0)] - pure fn ne(other: &visibility) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &visibility) -> bool { !(*self).eq(other) } } @@ -2170,30 +1560,6 @@ enum struct_field_kind { } impl struct_field_kind : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &struct_field_kind) -> bool { - match self { - named_field(ident_a, class_mutability_a, visibility_a) => { - match *other { - named_field(ident_b, class_mutability_b, visibility_b) - => { - ident_a == ident_b && - class_mutability_a == class_mutability_b && - visibility_a == visibility_b - } - unnamed_field => false - } - } - unnamed_field => { - match *other { - named_field(*) => false, - unnamed_field => true - } - } - } - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &struct_field_kind) -> bool { match (*self) { named_field(ident_a, class_mutability_a, visibility_a) => { @@ -2215,12 +1581,6 @@ impl struct_field_kind : cmp::Eq { } } } - #[cfg(stage0)] - pure fn ne(other: &struct_field_kind) -> bool { - !self.eq(other) - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &struct_field_kind) -> bool { !(*self).eq(other) } @@ -2287,17 +1647,6 @@ impl class_mutability : to_bytes::IterBytes { } impl class_mutability : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &class_mutability) -> bool { - match (self, (*other)) { - (class_mutable, class_mutable) => true, - (class_immutable, class_immutable) => true, - (class_mutable, _) => false, - (class_immutable, _) => false, - } - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &class_mutability) -> bool { match ((*self), (*other)) { (class_mutable, class_mutable) => true, @@ -2306,10 +1655,6 @@ impl class_mutability : cmp::Eq { (class_immutable, _) => false, } } - #[cfg(stage0)] - pure fn ne(other: &class_mutability) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &class_mutability) -> bool { !(*self).eq(other) } } diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index 859f5f1d502..3251ea5d2e9 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -12,25 +12,6 @@ enum path_elt { } impl path_elt : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &path_elt) -> bool { - match self { - path_mod(e0a) => { - match (*other) { - path_mod(e0b) => e0a == e0b, - _ => false - } - } - path_name(e0a) => { - match (*other) { - path_name(e0b) => e0a == e0b, - _ => false - } - } - } - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &path_elt) -> bool { match (*self) { path_mod(e0a) => { @@ -47,10 +28,6 @@ impl path_elt : cmp::Eq { } } } - #[cfg(stage0)] - pure fn ne(other: &path_elt) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &path_elt) -> bool { !(*self).eq(other) } } diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 94d78d0c55f..468704c9aff 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -338,19 +338,9 @@ enum inline_attr { } impl inline_attr : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &inline_attr) -> bool { - (self as uint) == ((*other) as uint) - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &inline_attr) -> bool { ((*self) as uint) == ((*other) as uint) } - #[cfg(stage0)] - pure fn ne(other: &inline_attr) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &inline_attr) -> bool { !(*self).eq(other) } } diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 2280986ab94..8126f1d7200 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -37,29 +37,11 @@ impl BytePos: Pos { pure fn to_uint(&self) -> uint { **self } } -#[cfg(stage0)] -impl BytePos: cmp::Eq { - pure fn eq(other: &BytePos) -> bool { *self == **other } - pure fn ne(other: &BytePos) -> bool { !self.eq(other) } -} - -#[cfg(stage1)] -#[cfg(stage2)] impl BytePos: cmp::Eq { pure fn eq(&self, other: &BytePos) -> bool { **self == **other } pure fn ne(&self, other: &BytePos) -> bool { !(*self).eq(other) } } -#[cfg(stage0)] -impl BytePos: cmp::Ord { - pure fn lt(other: &BytePos) -> bool { *self < **other } - pure fn le(other: &BytePos) -> bool { *self <= **other } - pure fn ge(other: &BytePos) -> bool { *self >= **other } - pure fn gt(other: &BytePos) -> bool { *self > **other } -} - -#[cfg(stage1)] -#[cfg(stage2)] impl BytePos: cmp::Ord { pure fn lt(&self, other: &BytePos) -> bool { **self < **other } pure fn le(&self, other: &BytePos) -> bool { **self <= **other } @@ -110,29 +92,11 @@ impl CharPos: Pos { pure fn to_uint(&self) -> uint { **self } } -#[cfg(stage0)] -impl CharPos: cmp::Eq { - pure fn eq(other: &CharPos) -> bool { *self == **other } - pure fn ne(other: &CharPos) -> bool { !self.eq(other) } -} - -#[cfg(stage1)] -#[cfg(stage2)] impl CharPos: cmp::Eq { pure fn eq(&self, other: &CharPos) -> bool { **self == **other } pure fn ne(&self, other: &CharPos) -> bool { !(*self).eq(other) } } -#[cfg(stage0)] -impl CharPos: cmp::Ord { - pure fn lt(other: &CharPos) -> bool { *self < **other } - pure fn le(other: &CharPos) -> bool { *self <= **other } - pure fn ge(other: &CharPos) -> bool { *self >= **other } - pure fn gt(other: &CharPos) -> bool { *self > **other } -} - -#[cfg(stage1)] -#[cfg(stage2)] impl CharPos: cmp::Ord { pure fn lt(&self, other: &CharPos) -> bool { **self < **other } pure fn le(&self, other: &CharPos) -> bool { **self <= **other } @@ -190,19 +154,9 @@ pub struct span { } impl span : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &span) -> bool { - return self.lo == (*other).lo && self.hi == (*other).hi; - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &span) -> bool { return (*self).lo == (*other).lo && (*self).hi == (*other).hi; } - #[cfg(stage0)] - pure fn ne(other: &span) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &span) -> bool { !(*self).eq(other) } } diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index a362c766c77..8784b3837f1 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -149,19 +149,9 @@ enum level { } impl level : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &level) -> bool { - (self as uint) == ((*other) as uint) - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &level) -> bool { ((*self) as uint) == ((*other) as uint) } - #[cfg(stage0)] - pure fn ne(other: &level) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &level) -> bool { !(*self).eq(other) } } diff --git a/src/libsyntax/ext/pipes/mod.rs b/src/libsyntax/ext/pipes/mod.rs new file mode 100644 index 00000000000..638ccad0143 --- /dev/null +++ b/src/libsyntax/ext/pipes/mod.rs @@ -0,0 +1,12 @@ +#[legacy_exports] +mod ast_builder; +#[legacy_exports] +mod parse_proto; +#[legacy_exports] +mod pipec; +#[legacy_exports] +mod proto; +#[legacy_exports] +mod check; +#[legacy_exports] +mod liveness; diff --git a/src/libsyntax/ext/pipes/proto.rs b/src/libsyntax/ext/pipes/proto.rs index 23e18478536..18caef0f72f 100644 --- a/src/libsyntax/ext/pipes/proto.rs +++ b/src/libsyntax/ext/pipes/proto.rs @@ -6,17 +6,6 @@ use ast_builder::{path, append_types}; enum direction { send, recv } impl direction : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &direction) -> bool { - match (self, (*other)) { - (send, send) => true, - (recv, recv) => true, - (send, _) => false, - (recv, _) => false, - } - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &direction) -> bool { match ((*self), (*other)) { (send, send) => true, @@ -25,10 +14,6 @@ impl direction : cmp::Eq { (recv, _) => false, } } - #[cfg(stage0)] - pure fn ne(other: &direction) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &direction) -> bool { !(*self).eq(other) } } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index dc7a7feff14..1db37418370 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -21,7 +21,6 @@ export extensions; trait ast_fold { fn fold_crate(crate) -> crate; - fn fold_crate_directive(&&v: @crate_directive) -> @crate_directive; fn fold_view_item(&&v: @view_item) -> @view_item; fn fold_foreign_item(&&v: @foreign_item) -> @foreign_item; fn fold_item(&&v: @item) -> Option<@item>; @@ -51,8 +50,6 @@ trait ast_fold { type ast_fold_precursor = @{ //unlike the others, item_ is non-trivial fold_crate: fn@(crate_, span, ast_fold) -> (crate_, span), - fold_crate_directive: fn@(crate_directive_, span, - ast_fold) -> (crate_directive_, span), fold_view_item: fn@(view_item_, ast_fold) -> view_item_, fold_foreign_item: fn@(&&v: @foreign_item, ast_fold) -> @foreign_item, fold_item: fn@(&&v: @item, ast_fold) -> Option<@item>, @@ -150,29 +147,12 @@ fn noop_fold_crate(c: crate_, fld: ast_fold) -> crate_ { let fold_attribute = |x| fold_attribute_(x, fld); return { - directives: vec::map(c.directives, |x| fld.fold_crate_directive(*x)), module: fld.fold_mod(c.module), attrs: vec::map(c.attrs, |x| fold_attribute(*x)), config: vec::map(c.config, |x| fold_meta_item(*x)) }; } -fn noop_fold_crate_directive(cd: crate_directive_, fld: ast_fold) -> - crate_directive_ { - return match cd { - cdir_src_mod(vis, id, attrs) => { - cdir_src_mod(vis, fld.fold_ident(id), - /* FIXME (#2543) */ copy attrs) - } - cdir_dir_mod(vis, id, cds, attrs) => { - cdir_dir_mod(vis, fld.fold_ident(id), - vec::map(cds, |x| fld.fold_crate_directive(*x)), - /* FIXME (#2543) */ copy attrs) - } - cdir_view_item(vi) => cdir_view_item(fld.fold_view_item(vi)), - } -} - fn noop_fold_view_item(vi: view_item_, _fld: ast_fold) -> view_item_ { return /* FIXME (#2543) */ copy vi; } @@ -636,7 +616,6 @@ fn noop_span(sp: span) -> span { return sp; } fn default_ast_fold() -> ast_fold_precursor { return @{fold_crate: wrap(noop_fold_crate), - fold_crate_directive: wrap(noop_fold_crate_directive), fold_view_item: noop_fold_view_item, fold_foreign_item: noop_fold_foreign_item, fold_item: noop_fold_item, @@ -667,12 +646,6 @@ impl ast_fold_precursor: ast_fold { let (n, s) = self.fold_crate(c.node, c.span, self as ast_fold); return {node: n, span: self.new_span(s)}; } - fn fold_crate_directive(&&c: @crate_directive) -> @crate_directive { - let (n, s) = self.fold_crate_directive(c.node, c.span, - self as ast_fold); - return @{node: n, - span: self.new_span(s)}; - } fn fold_view_item(&&x: @view_item) -> @view_item { return @{node: self.fold_view_item(x.node, self as ast_fold), diff --git a/src/libsyntax/parse.rs b/src/libsyntax/parse.rs index 3ddb03547cb..ccca4139c9b 100644 --- a/src/libsyntax/parse.rs +++ b/src/libsyntax/parse.rs @@ -1,5 +1,16 @@ //! The main parser interface +#[legacy_exports]; + +export parser; +export common; +export lexer; +export token; +export comments; +export prec; +export classify; +export attr; + export parse_sess; export new_parse_sess, new_parse_sess_special_handler; export next_node_id; @@ -51,40 +62,6 @@ fn new_parse_sess_special_handler(sh: span_handler, cm: @codemap::CodeMap) fn parse_crate_from_file(input: &Path, cfg: ast::crate_cfg, sess: parse_sess) -> @ast::crate { - if input.filetype() == Some(~".rc") { - parse_crate_from_crate_file(input, cfg, sess) - } else if input.filetype() == Some(~".rs") { - parse_crate_from_source_file(input, cfg, sess) - } else { - sess.span_diagnostic.handler().fatal(~"unknown input file type: " + - input.to_str()) - } -} - -fn parse_crate_from_crate_file(input: &Path, cfg: ast::crate_cfg, - sess: parse_sess) -> @ast::crate { - let p = new_crate_parser_from_file(sess, cfg, input); - let lo = p.span.lo; - let prefix = input.dir_path(); - let leading_attrs = p.parse_inner_attrs_and_next(); - let { inner: crate_attrs, next: first_cdir_attr } = leading_attrs; - let cdirs = p.parse_crate_directives(token::EOF, first_cdir_attr); - let cx = @{sess: sess, cfg: /* FIXME (#2543) */ copy p.cfg}; - let companionmod = input.filestem().map(|s| Path(*s)); - let (m, attrs) = eval::eval_crate_directives_to_mod( - cx, cdirs, &prefix, &companionmod); - let mut hi = p.span.hi; - p.expect(token::EOF); - p.abort_if_errors(); - return @ast_util::respan(ast_util::mk_sp(lo, hi), - {directives: cdirs, - module: m, - attrs: vec::append(crate_attrs, attrs), - config: /* FIXME (#2543) */ copy p.cfg}); -} - -fn parse_crate_from_source_file(input: &Path, cfg: ast::crate_cfg, - sess: parse_sess) -> @ast::crate { let p = new_crate_parser_from_file(sess, cfg, input); let r = p.parse_crate_mod(cfg); return r; @@ -175,6 +152,18 @@ fn new_parser_from_file(sess: parse_sess, cfg: ast::crate_cfg, path: &Path) -> Result<Parser, ~str> { match io::read_whole_file_str(path) { result::Ok(move src) => { + + // HACK: If the file contains a special token use a different + // source file. Used to send the stage1+ parser (the stage0 parser + // doesn't have this hack) to a different crate file. + // Transitional. Remove me. + let src = if src.starts_with("// DIVERT") { + let actual_path = &path.with_filestem("alternate_crate"); + result::unwrap(io::read_whole_file_str(actual_path)) + } else { + move src + }; + let filemap = sess.cm.new_filemap(path.to_str(), @move src); let srdr = lexer::new_string_reader(sess.span_diagnostic, filemap, sess.interner); diff --git a/src/libsyntax/parse/comments.rs b/src/libsyntax/parse/comments.rs index 3cb6b08d976..4f7bfb0d4e9 100644 --- a/src/libsyntax/parse/comments.rs +++ b/src/libsyntax/parse/comments.rs @@ -20,21 +20,9 @@ enum cmnt_style { } impl cmnt_style : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &cmnt_style) -> bool { - (self as uint) == ((*other) as uint) - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &cmnt_style) -> bool { ((*self) as uint) == ((*other) as uint) } - #[cfg(stage0)] - pure fn ne(other: &cmnt_style) -> bool { - (self as uint) != ((*other) as uint) - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &cmnt_style) -> bool { ((*self) as uint) != ((*other) as uint) } diff --git a/src/libsyntax/parse/eval.rs b/src/libsyntax/parse/eval.rs index 78a47ec09c7..cdfd8a9bcec 100644 --- a/src/libsyntax/parse/eval.rs +++ b/src/libsyntax/parse/eval.rs @@ -5,6 +5,7 @@ use codemap::span; export eval_crate_directives_to_mod; export eval_src_mod; +export eval_src_mod_from_path; type ctx = @{sess: parse::parse_sess, @@ -84,15 +85,23 @@ fn cdir_path_opt(default: ~str, attrs: ~[ast::attribute]) -> ~str { } } -fn eval_src_mod(cx: ctx, prefix: &Path, id: ast::ident, +fn eval_src_mod(cx: ctx, prefix: &Path, outer_attrs: ~[ast::attribute], - sp: span) -> (ast::item_, ~[ast::attribute]) { + id: ast::ident, sp: span + ) -> (ast::item_, ~[ast::attribute]) { let file_path = Path(cdir_path_opt( cx.sess.interner.get(id) + ~".rs", outer_attrs)); - let full_path = if file_path.is_absolute { - copy file_path + eval_src_mod_from_path(cx, prefix, &file_path, outer_attrs, sp) +} + +fn eval_src_mod_from_path(cx: ctx, prefix: &Path, path: &Path, + outer_attrs: ~[ast::attribute], + sp: span + ) -> (ast::item_, ~[ast::attribute]) { + let full_path = if path.is_absolute { + copy *path } else { - prefix.push_many(file_path.components) + prefix.push_many(path.components) }; let p0 = new_sub_parser_from_file(cx.sess, cx.cfg, @@ -121,7 +130,7 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: &Path, items: &mut ~[@ast::item]) { match cdir.node { ast::cdir_src_mod(vis, id, attrs) => { - let (m, mod_attrs) = eval_src_mod(cx, prefix, id, attrs, cdir.span); + let (m, mod_attrs) = eval_src_mod(cx, prefix, attrs, id, cdir.span); let i = mk_item(cx, cdir.span.lo, cdir.span.hi, /* FIXME (#2543) */ copy id, m, vis, mod_attrs); diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs new file mode 100644 index 00000000000..a7c5f20fedf --- /dev/null +++ b/src/libsyntax/parse/mod.rs @@ -0,0 +1,28 @@ + +#[legacy_exports] +mod lexer; +#[legacy_exports] +mod parser; +#[legacy_exports] +mod token; +#[legacy_exports] +mod comments; +#[legacy_exports] +mod attr; +#[legacy_exports] + +/// Common routines shared by parser mods +#[legacy_exports] +mod common; + +/// Functions dealing with operator precedence +#[legacy_exports] +mod prec; + +/// Routines the parser uses to classify AST nodes +#[legacy_exports] +mod classify; + +/// Reporting obsolete syntax +#[legacy_exports] +mod obsolete; diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index a6a7736e3d0..07ce7f4a268 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -29,21 +29,9 @@ pub enum ObsoleteSyntax { } impl ObsoleteSyntax : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &ObsoleteSyntax) -> bool { - self as uint == (*other) as uint - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &ObsoleteSyntax) -> bool { (*self) as uint == (*other) as uint } - #[cfg(stage0)] - pure fn ne(other: &ObsoleteSyntax) -> bool { - !self.eq(other) - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &ObsoleteSyntax) -> bool { !(*self).eq(other) } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index e4d77e7da09..d95f4fb3f75 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -27,9 +27,8 @@ use ast::{_mod, add, arg, arm, attribute, bind_by_ref, bind_by_implicit_ref, bind_by_value, bind_by_move, bitand, bitor, bitxor, blk, blk_check_mode, box, by_copy, by_move, by_ref, by_val, capture_clause, - capture_item, cdir_dir_mod, cdir_src_mod, cdir_view_item, - class_immutable, class_mutable, - crate, crate_cfg, crate_directive, decl, decl_item, decl_local, + capture_item, class_immutable, class_mutable, + crate, crate_cfg, decl, decl_item, decl_local, default_blk, deref, div, enum_def, enum_variant_kind, expl, expr, expr_, expr_addr_of, expr_match, expr_again, expr_assert, expr_assign, expr_assign_op, expr_binary, expr_block, expr_break, @@ -2967,17 +2966,10 @@ impl Parser { fn parse_item_mod(outer_attrs: ~[ast::attribute]) -> item_info { let id_span = self.span; let id = self.parse_ident(); - if self.token == token::SEMI { + let info_ = if self.token == token::SEMI { self.bump(); // This mod is in an external file. Let's go get it! - let eval_ctx = @{ - sess: self.sess, - cfg: self.cfg - }; - let prefix = Path(self.sess.cm.span_to_filename(copy self.span)); - let prefix = prefix.dir_path(); - let (m, attrs) = eval::eval_src_mod(eval_ctx, &prefix, id, - outer_attrs, id_span); + let (m, attrs) = self.eval_src_mod(id, outer_attrs, id_span); (id, m, Some(move attrs)) } else { self.expect(token::LBRACE); @@ -2985,6 +2977,83 @@ impl Parser { let m = self.parse_mod_items(token::RBRACE, inner_attrs.next); self.expect(token::RBRACE); (id, item_mod(m), Some(inner_attrs.inner)) + }; + + // XXX: Transitionary hack to do the template work inside core + // (int-template, iter-trait). If there's a 'merge' attribute + // on the mod, then we'll go and suck in another file and merge + // its contents + match ::attr::first_attr_value_str_by_name(outer_attrs, ~"merge") { + Some(path) => { + let prefix = Path( + self.sess.cm.span_to_filename(copy self.span)); + let prefix = prefix.dir_path(); + let path = Path(path); + let (new_mod_item, new_attrs) = self.eval_src_mod_from_path( + prefix, path, ~[], id_span); + + let (main_id, main_mod_item, main_attrs) = info_; + let main_attrs = main_attrs.get(); + + let (main_mod, new_mod) = + match (main_mod_item, new_mod_item) { + (item_mod(m), item_mod(n)) => (m, n), + _ => self.bug(~"parsed mod item should be mod") + }; + let merged_mod = { + view_items: main_mod.view_items + new_mod.view_items, + items: main_mod.items + new_mod.items + }; + + let merged_attrs = main_attrs + new_attrs; + (main_id, item_mod(merged_mod), Some(merged_attrs)) + } + None => info_ + } + } + + fn eval_src_mod(id: ast::ident, + outer_attrs: ~[ast::attribute], + id_sp: span) -> (ast::item_, ~[ast::attribute]) { + let prefix = Path(self.sess.cm.span_to_filename(copy self.span)); + let prefix = prefix.dir_path(); + let default_path = self.sess.interner.get(id) + ~".rs"; + let file_path = match ::attr::first_attr_value_str_by_name( + outer_attrs, ~"path") { + + Some(d) => d, + None => default_path + }; + + let file_path = Path(file_path); + self.eval_src_mod_from_path(prefix, file_path, + outer_attrs, id_sp) + } + + fn eval_src_mod_from_path(prefix: Path, path: Path, + outer_attrs: ~[ast::attribute], + id_sp: span + ) -> (ast::item_, ~[ast::attribute]) { + + let full_path = if path.is_absolute { + path + } else { + prefix.push_many(path.components) + }; + let p0 = + new_sub_parser_from_file(self.sess, self.cfg, + &full_path, id_sp); + let inner_attrs = p0.parse_inner_attrs_and_next(); + let mod_attrs = vec::append(outer_attrs, inner_attrs.inner); + let first_item_outer_attrs = inner_attrs.next; + let m0 = p0.parse_mod_items(token::EOF, first_item_outer_attrs); + return (ast::item_mod(m0), mod_attrs); + + fn cdir_path_opt(default: ~str, attrs: ~[ast::attribute]) -> ~str { + match ::attr::first_attr_value_str_by_name(attrs, ~"path") { + Some(d) => d, + None => default + } } } @@ -3702,8 +3771,7 @@ impl Parser { let first_item_outer_attrs = crate_attrs.next; let m = self.parse_mod_items(token::EOF, first_item_outer_attrs); return @spanned(lo, self.span.lo, - {directives: ~[], - module: m, + {module: m, attrs: crate_attrs.inner, config: self.cfg}); } @@ -3714,94 +3782,12 @@ impl Parser { _ => self.fatal(~"expected string literal") } } - - // Logic for parsing crate files (.rc) - // - // Each crate file is a sequence of directives. - // - // Each directive imperatively extends its environment with 0 or more - // items. - fn parse_crate_directive(first_outer_attr: ~[attribute]) -> - crate_directive { - - // Collect the next attributes - let outer_attrs = vec::append(first_outer_attr, - self.parse_outer_attributes()); - // In a crate file outer attributes are only going to apply to mods - let expect_mod = vec::len(outer_attrs) > 0u; - - let lo = self.span.lo; - let vis = self.parse_visibility(); - if expect_mod || self.is_keyword(~"mod") { - - self.expect_keyword(~"mod"); - - let id = self.parse_ident(); - match self.token { - // mod x = "foo.rs"; - token::SEMI => { - let mut hi = self.span.hi; - self.bump(); - return spanned(lo, hi, cdir_src_mod(vis, id, outer_attrs)); - } - // mod x = "foo_dir" { ...directives... } - token::LBRACE => { - self.bump(); - let inner_attrs = self.parse_inner_attrs_and_next(); - let mod_attrs = vec::append(outer_attrs, inner_attrs.inner); - let next_outer_attr = inner_attrs.next; - let cdirs = self.parse_crate_directives(token::RBRACE, - next_outer_attr); - let mut hi = self.span.hi; - self.expect(token::RBRACE); - return spanned(lo, hi, - cdir_dir_mod(vis, id, cdirs, mod_attrs)); - } - _ => self.unexpected() - } - } else if self.is_view_item() { - let vi = self.parse_view_item(outer_attrs, vis); - return spanned(lo, vi.span.hi, cdir_view_item(vi)); - } - return self.fatal(~"expected crate directive"); - } - - fn parse_crate_directives(term: token::Token, - first_outer_attr: ~[attribute]) -> - ~[@crate_directive] { - - // This is pretty ugly. If we have an outer attribute then we can't - // accept seeing the terminator next, so if we do see it then fail the - // same way parse_crate_directive would - if vec::len(first_outer_attr) > 0u && self.token == term { - self.expect_keyword(~"mod"); - } - - let mut cdirs: ~[@crate_directive] = ~[]; - let mut first_outer_attr = first_outer_attr; - while self.token != term { - let cdir = @self.parse_crate_directive(first_outer_attr); - cdirs.push(cdir); - first_outer_attr = ~[]; - } - return cdirs; - } } impl restriction : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &restriction) -> bool { - (self as uint) == ((*other) as uint) - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &restriction) -> bool { ((*self) as uint) == ((*other) as uint) } - #[cfg(stage0)] - pure fn ne(other: &restriction) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &restriction) -> bool { !(*self).eq(other) } } diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 7b15f00d761..99c12be4980 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -465,294 +465,13 @@ fn reserved_keyword_table() -> HashMap<~str, ()> { } impl binop : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &binop) -> bool { - (self as uint) == ((*other) as uint) - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &binop) -> bool { ((*self) as uint) == ((*other) as uint) } - #[cfg(stage0)] - pure fn ne(other: &binop) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &binop) -> bool { !(*self).eq(other) } } impl Token : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &Token) -> bool { - match self { - EQ => { - match (*other) { - EQ => true, - _ => false - } - } - LT => { - match (*other) { - LT => true, - _ => false - } - } - LE => { - match (*other) { - LE => true, - _ => false - } - } - EQEQ => { - match (*other) { - EQEQ => true, - _ => false - } - } - NE => { - match (*other) { - NE => true, - _ => false - } - } - GE => { - match (*other) { - GE => true, - _ => false - } - } - GT => { - match (*other) { - GT => true, - _ => false - } - } - ANDAND => { - match (*other) { - ANDAND => true, - _ => false - } - } - OROR => { - match (*other) { - OROR => true, - _ => false - } - } - NOT => { - match (*other) { - NOT => true, - _ => false - } - } - TILDE => { - match (*other) { - TILDE => true, - _ => false - } - } - BINOP(e0a) => { - match (*other) { - BINOP(e0b) => e0a == e0b, - _ => false - } - } - BINOPEQ(e0a) => { - match (*other) { - BINOPEQ(e0b) => e0a == e0b, - _ => false - } - } - AT => { - match (*other) { - AT => true, - _ => false - } - } - DOT => { - match (*other) { - DOT => true, - _ => false - } - } - DOTDOT => { - match (*other) { - DOTDOT => true, - _ => false - } - } - ELLIPSIS => { - match (*other) { - ELLIPSIS => true, - _ => false - } - } - COMMA => { - match (*other) { - COMMA => true, - _ => false - } - } - SEMI => { - match (*other) { - SEMI => true, - _ => false - } - } - COLON => { - match (*other) { - COLON => true, - _ => false - } - } - MOD_SEP => { - match (*other) { - MOD_SEP => true, - _ => false - } - } - RARROW => { - match (*other) { - RARROW => true, - _ => false - } - } - LARROW => { - match (*other) { - LARROW => true, - _ => false - } - } - DARROW => { - match (*other) { - DARROW => true, - _ => false - } - } - FAT_ARROW => { - match (*other) { - FAT_ARROW => true, - _ => false - } - } - LPAREN => { - match (*other) { - LPAREN => true, - _ => false - } - } - RPAREN => { - match (*other) { - RPAREN => true, - _ => false - } - } - LBRACKET => { - match (*other) { - LBRACKET => true, - _ => false - } - } - RBRACKET => { - match (*other) { - RBRACKET => true, - _ => false - } - } - LBRACE => { - match (*other) { - LBRACE => true, - _ => false - } - } - RBRACE => { - match (*other) { - RBRACE => true, - _ => false - } - } - POUND => { - match (*other) { - POUND => true, - _ => false - } - } - DOLLAR => { - match (*other) { - DOLLAR => true, - _ => false - } - } - LIT_INT(e0a, e1a) => { - match (*other) { - LIT_INT(e0b, e1b) => e0a == e0b && e1a == e1b, - _ => false - } - } - LIT_UINT(e0a, e1a) => { - match (*other) { - LIT_UINT(e0b, e1b) => e0a == e0b && e1a == e1b, - _ => false - } - } - LIT_INT_UNSUFFIXED(e0a) => { - match (*other) { - LIT_INT_UNSUFFIXED(e0b) => e0a == e0b, - _ => false - } - } - LIT_FLOAT(e0a, e1a) => { - match (*other) { - LIT_FLOAT(e0b, e1b) => e0a == e0b && e1a == e1b, - _ => false - } - } - LIT_FLOAT_UNSUFFIXED(e0a) => { - match (*other) { - LIT_FLOAT_UNSUFFIXED(e0b) => e0a == e0b, - _ => false - } - } - LIT_STR(e0a) => { - match (*other) { - LIT_STR(e0b) => e0a == e0b, - _ => false - } - } - IDENT(e0a, e1a) => { - match (*other) { - IDENT(e0b, e1b) => e0a == e0b && e1a == e1b, - _ => false - } - } - UNDERSCORE => { - match (*other) { - UNDERSCORE => true, - _ => false - } - } - INTERPOLATED(_) => { - match (*other) { - INTERPOLATED(_) => true, - _ => false - } - } - DOC_COMMENT(e0a) => { - match (*other) { - DOC_COMMENT(e0b) => e0a == e0b, - _ => false - } - } - EOF => { - match (*other) { - EOF => true, - _ => false - } - } - } - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &Token) -> bool { match (*self) { EQ => { @@ -1021,10 +740,6 @@ impl Token : cmp::Eq { } } } - #[cfg(stage0)] - pure fn ne(other: &Token) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &Token) -> bool { !(*self).eq(other) } } diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index e4bd3e92cc4..014d564b84e 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -56,17 +56,6 @@ use dvec::DVec; enum breaks { consistent, inconsistent, } impl breaks : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &breaks) -> bool { - match (self, (*other)) { - (consistent, consistent) => true, - (inconsistent, inconsistent) => true, - (consistent, _) => false, - (inconsistent, _) => false, - } - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &breaks) -> bool { match ((*self), (*other)) { (consistent, consistent) => true, @@ -75,10 +64,6 @@ impl breaks : cmp::Eq { (inconsistent, _) => false, } } - #[cfg(stage0)] - pure fn ne(other: &breaks) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &breaks) -> bool { !(*self).eq(other) } } diff --git a/src/libsyntax/syntax.rc b/src/libsyntax/syntax.rc index 2837e8fc64f..d5a28a716ec 100644 --- a/src/libsyntax/syntax.rc +++ b/src/libsyntax/syntax.rc @@ -40,118 +40,89 @@ mod fold; mod util { #[legacy_exports]; #[legacy_exports] + #[path = "util/interner.rs"] mod interner; } -mod parse { - #[legacy_exports]; - export parser; - export common; - export lexer; - export token; - export comments; - export prec; - export classify; - export attr; - - #[legacy_exports] - mod eval; - #[legacy_exports] - mod lexer; - #[legacy_exports] - mod parser; - #[legacy_exports] - mod token; - #[legacy_exports] - mod comments; - #[legacy_exports] - mod attr; - #[legacy_exports] - - /// Common routines shared by parser mods - #[legacy_exports] - mod common; - - /// Functions dealing with operator precedence - #[legacy_exports] - mod prec; - - /// Routines the parser uses to classify AST nodes - #[legacy_exports] - mod classify; - - /// Reporting obsolete syntax - #[legacy_exports] - mod obsolete; -} +#[merge = "parse/mod.rs"] +mod parse; mod print { #[legacy_exports]; #[legacy_exports] + #[path = "print/pp.rs"] mod pp; #[legacy_exports] + #[path = "print/pprust.rs"] mod pprust; } mod ext { #[legacy_exports]; #[legacy_exports] + #[path = "ext/base.rs"] mod base; #[legacy_exports] + #[path = "ext/expand.rs"] mod expand; #[legacy_exports] + #[path = "ext/qquote.rs"] mod qquote; + #[path = "ext/quote.rs"] mod quote; + #[path = "ext/deriving.rs"] mod deriving; #[legacy_exports] + #[path = "ext/build.rs"] mod build; mod tt { #[legacy_exports]; #[legacy_exports] + #[path = "ext/tt/transcribe.rs"] mod transcribe; #[legacy_exports] + #[path = "ext/tt/macro_parser.rs"] mod macro_parser; #[legacy_exports] + #[path = "ext/tt/macro_rules.rs"] mod macro_rules; } #[legacy_exports] + #[path = "ext/simplext.rs"] mod simplext; #[legacy_exports] + #[path = "ext/fmt.rs"] mod fmt; #[legacy_exports] + #[path = "ext/env.rs"] mod env; #[legacy_exports] + #[path = "ext/concat_idents.rs"] mod concat_idents; #[legacy_exports] + #[path = "ext/ident_to_str.rs"] mod ident_to_str; #[legacy_exports] + #[path = "ext/log_syntax.rs"] mod log_syntax; #[legacy_exports] + #[path = "ext/auto_serialize.rs"] mod auto_serialize; #[legacy_exports] + #[path = "ext/source_util.rs"] mod source_util; - mod pipes { - #[legacy_exports]; - #[legacy_exports] - mod ast_builder; - #[legacy_exports] - mod parse_proto; - #[legacy_exports] - mod pipec; - #[legacy_exports] - mod proto; - #[legacy_exports] - mod check; - #[legacy_exports] - mod liveness; - } + #[legacy_exports] + #[path = "ext/pipes.rs"] + #[merge = "ext/pipes/mod.rs"] + mod pipes; #[legacy_exports] + #[path = "ext/trace_macros.rs"] mod trace_macros; } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index ae0de2add81..afd928a9fbc 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -93,16 +93,6 @@ fn visit_crate<E>(c: crate, e: E, v: vt<E>) { v.visit_mod(c.node.module, c.span, crate_node_id, e, v); } -fn visit_crate_directive<E>(cd: @crate_directive, e: E, v: vt<E>) { - match cd.node { - cdir_src_mod(_, _, _) => (), - cdir_dir_mod(_, _, cdirs, _) => for cdirs.each |cdir| { - visit_crate_directive(*cdir, e, v); - }, - cdir_view_item(vi) => v.visit_view_item(vi, e, v), - } -} - fn visit_mod<E>(m: _mod, _sp: span, _id: node_id, e: E, v: vt<E>) { for m.view_items.each |vi| { v.visit_view_item(*vi, e, v); } for m.items.each |i| { v.visit_item(*i, e, v); } |
