Permalink
Browse files

Convert class methods to impl methods. Stop parsing class methods

  • Loading branch information...
1 parent bea6fe0 commit 93d3b8aa6b681a8add60e4a22a5c41e7f7ce7557 @brson brson committed Sep 8, 2012
Showing with 398 additions and 195 deletions.
  1. +0 −1 src/compiletest/procsrv.rs
  2. +48 −37 src/libcore/pipes.rs
  3. +7 −1 src/libstd/comm.rs
  4. +3 −0 src/libsyntax/ext/pipes/proto.rs
  5. +20 −25 src/libsyntax/parse/parser.rs
  6. +3 −0 src/rustc/middle/lang_items.rs
  7. +24 −12 src/rustc/middle/resolve.rs
  8. +3 −0 src/rustc/middle/typeck/check/method.rs
  9. +3 −0 src/rustc/middle/typeck/coherence.rs
  10. +3 −1 src/test/auxiliary/cci_class_2.rs
  11. +5 −4 src/test/auxiliary/cci_class_3.rs
  12. +13 −7 src/test/auxiliary/cci_class_4.rs
  13. +4 −1 src/test/auxiliary/cci_class_5.rs
  14. +6 −5 src/test/auxiliary/cci_class_6.rs
  15. +29 −22 src/test/auxiliary/cci_class_cast.rs
  16. +5 −1 src/test/bench/task-perf-word-count-generic.rs
  17. +3 −0 src/test/compile-fail/assign-to-method.rs
  18. +18 −9 src/test/compile-fail/class-cast-to-trait.rs
  19. +4 −1 src/test/compile-fail/class-missing-self.rs
  20. +5 −0 src/test/compile-fail/issue-2356.rs
  21. +3 −0 src/test/compile-fail/issue-2487-b.rs
  22. +3 −0 src/test/compile-fail/issue-3021-b.rs
  23. +2 −0 src/test/compile-fail/mutable-class-fields-2.rs
  24. +1 −0 src/test/compile-fail/private-method-cross-crate.rs
  25. +9 −3 src/test/compile-fail/private-method.rs
  26. +2 −0 src/test/compile-fail/regions-addr-of-self.rs
  27. +2 −0 src/test/compile-fail/regions-addr-of-upvar-self.rs
  28. +26 −13 src/test/run-pass/class-cast-to-trait-multiple-types.rs
  29. +15 −8 src/test/run-pass/class-cast-to-trait.rs
  30. +2 −0 src/test/run-pass/class-exports.rs
  31. +15 −8 src/test/run-pass/class-impl-very-parameterized-trait.rs
  32. +19 −10 src/test/run-pass/class-implement-trait-cross-crate.rs
  33. +14 −7 src/test/run-pass/class-implement-traits.rs
  34. +3 −0 src/test/run-pass/class-methods.rs
  35. +2 −0 src/test/run-pass/class-poly-methods.rs
  36. +13 −7 src/test/run-pass/class-separate-impl.rs
  37. +2 −0 src/test/run-pass/class-typarams.rs
  38. +2 −0 src/test/run-pass/classes-simple-method.rs
  39. +13 −7 src/test/run-pass/classes.rs
  40. +4 −1 src/test/run-pass/issue-2288.rs
  41. +3 −0 src/test/run-pass/issue-2311-2.rs
  42. +3 −0 src/test/run-pass/issue-2445-b.rs
  43. +3 −0 src/test/run-pass/issue-2445.rs
  44. +3 −0 src/test/run-pass/issue-2487-a.rs
  45. +2 −0 src/test/run-pass/issue-2502.rs
  46. +6 −0 src/test/run-pass/issue-2718.rs
  47. +4 −1 src/test/run-pass/issue-2936.rs
  48. +3 −0 src/test/run-pass/nested-class.rs
  49. +2 −0 src/test/run-pass/private-class-field.rs
  50. +6 −1 src/test/run-pass/private-method.rs
  51. +4 −1 src/test/run-pass/resource-destruct.rs
  52. +1 −1 src/test/run-pass/task-comm-6.rs
@@ -1,7 +1,6 @@
import run::spawn_process;
import io::{ReaderUtil, WriterUtil};
import libc::{c_int, pid_t};
-import pipes::chan;
export run;
View
@@ -164,7 +164,17 @@ struct PacketHeader {
// This is a reinterpret_cast of a ~buffer, that can also be cast
// to a buffer_header if need be.
mut buffer: *libc::c_void,
+}
+
+fn PacketHeader() -> PacketHeader {
+ PacketHeader {
+ state: Empty,
+ blocked_task: ptr::null(),
+ buffer: ptr::null()
+ }
+}
+impl PacketHeader {
// Returns the old state.
unsafe fn mark_blocked(this: *rust_task) -> State {
rustrt::rust_task_ref(this);
@@ -196,14 +206,6 @@ struct PacketHeader {
}
}
-fn PacketHeader() -> PacketHeader {
- PacketHeader {
- state: Empty,
- blocked_task: ptr::null(),
- buffer: ptr::null()
- }
-}
-
#[doc(hidden)]
type Packet<T: Send> = {
header: PacketHeader,
@@ -794,6 +796,21 @@ struct SendPacketBuffered<T: Send, Tbuffer: Send> {
// "none"
// } else { "some" }); }
}
+}
+
+fn SendPacketBuffered<T: Send, Tbuffer: Send>(p: *Packet<T>)
+ -> SendPacketBuffered<T, Tbuffer> {
+ //debug!("take send %?", p);
+ SendPacketBuffered {
+ p: Some(p),
+ buffer: unsafe {
+ Some(BufferResource(
+ get_buffer(ptr::addr_of((*p).header))))
+ }
+ }
+}
+
+impl<T: Send, Tbuffer: Send> SendPacketBuffered<T, Tbuffer> {
fn unwrap() -> *Packet<T> {
let mut p = None;
p <-> self.p;
@@ -820,18 +837,6 @@ struct SendPacketBuffered<T: Send, Tbuffer: Send> {
}
}
-fn SendPacketBuffered<T: Send, Tbuffer: Send>(p: *Packet<T>)
- -> SendPacketBuffered<T, Tbuffer> {
- //debug!("take send %?", p);
- SendPacketBuffered {
- p: Some(p),
- buffer: unsafe {
- Some(BufferResource(
- get_buffer(ptr::addr_of((*p).header))))
- }
- }
-}
-
// XXX remove me
#[cfg(stage0)]
#[allow(non_camel_case_types)]
@@ -858,7 +863,7 @@ fn recv_packet<T: Send>(p: *packet<T>) -> RecvPacket<T> {
RecvPacket(p)
}
-struct RecvPacketBuffered<T: Send, Tbuffer: Send> : Selectable {
+struct RecvPacketBuffered<T: Send, Tbuffer: Send> {
mut p: Option<*Packet<T>>,
mut buffer: Option<BufferResource<Tbuffer>>,
drop {
@@ -875,6 +880,9 @@ struct RecvPacketBuffered<T: Send, Tbuffer: Send> : Selectable {
// "none"
// } else { "some" }); }
}
+}
+
+impl<T: Send, Tbuffer: Send> RecvPacketBuffered<T, Tbuffer> : Selectable {
fn unwrap() -> *Packet<T> {
let mut p = None;
p <-> self.p;
@@ -1095,9 +1103,27 @@ impl<T: Send> Port<T>: Recv<T> {
}
}
+impl<T: Send> Port<T>: Selectable {
+ pure fn header() -> *PacketHeader unchecked {
+ match self.endp {
+ Some(endp) => endp.header(),
+ None => fail ~"peeking empty stream"
+ }
+ }
+}
+
/// Treat many ports as one.
-struct PortSet<T: Send> : Recv<T> {
+struct PortSet<T: Send> {
mut ports: ~[pipes::Port<T>],
+}
+
+fn PortSet<T: Send>() -> PortSet<T>{
+ PortSet {
+ ports: ~[]
+ }
+}
+
+impl<T: Send> PortSet<T> : Recv<T> {
fn add(+port: pipes::Port<T>) {
vec::push(self.ports, move port)
@@ -1145,21 +1171,6 @@ struct PortSet<T: Send> : Recv<T> {
}
}
-fn PortSet<T: Send>() -> PortSet<T>{
- PortSet {
- ports: ~[]
- }
-}
-
-impl<T: Send> Port<T>: Selectable {
- pure fn header() -> *PacketHeader unchecked {
- match self.endp {
- Some(endp) => endp.header(),
- None => fail ~"peeking empty stream"
- }
- }
-}
-
/// A channel that can be shared between many senders.
type SharedChan<T: Send> = unsafe::Exclusive<Chan<T>>;
View
@@ -13,18 +13,22 @@ use pipes::{Channel, Recv, Chan, Port, Selectable};
export DuplexStream;
/// An extension of `pipes::stream` that allows both sending and receiving.
-struct DuplexStream<T: Send, U: Send> : Channel<T>, Recv<U>, Selectable {
+struct DuplexStream<T: Send, U: Send> {
priv chan: Chan<T>,
priv port: Port <U>,
+}
+impl<T: Send, U: Send> DuplexStream<T, U> : Channel<T> {
fn send(+x: T) {
self.chan.send(x)
}
fn try_send(+x: T) -> bool {
self.chan.try_send(x)
}
+}
+impl<T: Send, U: Send> DuplexStream<T, U> : Recv<U> {
fn recv() -> U {
self.port.recv()
}
@@ -36,7 +40,9 @@ struct DuplexStream<T: Send, U: Send> : Channel<T>, Recv<U>, Selectable {
pure fn peek() -> bool {
self.port.peek()
}
+}
+impl<T: Send, U: Send> DuplexStream<T, U> : Selectable {
pure fn header() -> *pipes::PacketHeader {
self.port.header()
}
@@ -134,6 +134,9 @@ struct protocol_ {
states: DVec<state>,
mut bounded: Option<bool>,
+}
+
+impl protocol_ {
/// Get a state.
fn get_state(name: ~str) -> state {
@@ -242,7 +242,9 @@ struct parser {
obsolete_set: hashmap<ObsoleteSyntax, ()>,
drop {} /* do not copy the parser; its state is tied to outside state */
+}
+impl parser {
fn bump() {
self.last_span = self.span;
let next = if self.buffer_start == self.buffer_end {
@@ -2776,32 +2778,25 @@ struct parser {
let obsolete_let = self.eat_obsolete_ident("let");
if obsolete_let { self.obsolete(copy self.last_span, ObsoleteLet) }
- if (obsolete_let || self.token_is_keyword(~"mut", copy self.token) ||
- !self.is_any_keyword(copy self.token)) &&
- !self.token_is_pound_or_doc_comment(self.token) {
- let a_var = self.parse_instance_var(vis);
- match self.token {
- token::SEMI => {
- self.obsolete(copy self.span, ObsoleteFieldTerminator);
- self.bump();
- }
- token::COMMA => {
- self.bump();
- }
- token::RBRACE => {}
- _ => {
- self.span_fatal(copy self.span,
- fmt!("expected `;`, `,`, or '}' but \
- found `%s`",
- token_to_str(self.reader,
- self.token)));
- }
- }
- return a_var;
- } else {
- let m = self.parse_method(vis);
- return @method_member(m);
+ let a_var = self.parse_instance_var(vis);
+ match self.token {
+ token::SEMI => {
+ self.obsolete(copy self.span, ObsoleteFieldTerminator);
+ self.bump();
+ }
+ token::COMMA => {
+ self.bump();
+ }
+ token::RBRACE => {}
+ _ => {
+ self.span_fatal(copy self.span,
+ fmt!("expected `;`, `,`, or '}' but \
+ found `%s`",
+ token_to_str(self.reader,
+ self.token)));
+ }
}
+ return a_var;
}
fn parse_dtor(attrs: ~[attribute]) -> class_contents {
@@ -120,6 +120,9 @@ struct LanguageItemCollector {
session: session,
item_refs: hashmap<~str,&mut Option<def_id>>,
+}
+
+impl LanguageItemCollector {
fn match_and_collect_meta_item(item_def_id: def_id,
meta_item: meta_item) {
@@ -379,14 +379,6 @@ struct ImportResolution {
mut type_target: Option<Target>,
mut used: bool,
-
- fn target_for_namespace(namespace: Namespace) -> Option<Target> {
- match namespace {
- ModuleNS => return copy self.module_target,
- TypeNS => return copy self.type_target,
- ValueNS => return copy self.value_target
- }
- }
}
fn ImportResolution(span: span) -> ImportResolution {
@@ -400,6 +392,16 @@ fn ImportResolution(span: span) -> ImportResolution {
}
}
+impl ImportResolution {
+ fn target_for_namespace(namespace: Namespace) -> Option<Target> {
+ match namespace {
+ ModuleNS => return copy self.module_target,
+ TypeNS => return copy self.type_target,
+ ValueNS => return copy self.value_target
+ }
+ }
+}
+
/// The link from a module up to its nearest parent node.
enum ParentLink {
NoParentLink,
@@ -448,10 +450,6 @@ struct Module {
// The index of the import we're resolving.
mut resolved_import_count: uint,
-
- fn all_imports_resolved() -> bool {
- return self.imports.len() == self.resolved_import_count;
- }
}
fn Module(parent_link: ParentLink, def_id: Option<def_id>) -> Module {
@@ -468,6 +466,12 @@ fn Module(parent_link: ParentLink, def_id: Option<def_id>) -> Module {
}
}
+impl Module {
+ fn all_imports_resolved() -> bool {
+ return self.imports.len() == self.resolved_import_count;
+ }
+}
+
// XXX: This is a workaround due to is_none in the standard library mistakenly
// requiring a T:copy.
@@ -518,6 +522,9 @@ struct NameBindings {
mut module_span: Option<span>,
mut type_span: Option<span>,
mut value_span: Option<span>,
+}
+
+impl NameBindings {
/// Creates a new module in this set of name bindings.
fn define_module(parent_link: ParentLink, def_id: Option<def_id>,
@@ -627,7 +634,9 @@ fn NameBindings() -> NameBindings {
/// Interns the names of the primitive types.
struct PrimitiveTypeTable {
primitive_types: hashmap<Atom,prim_ty>,
+}
+impl PrimitiveTypeTable {
fn intern(intr: ident_interner, string: @~str,
primitive_type: prim_ty) {
let atom = intr.intern(string);
@@ -773,6 +782,9 @@ struct Resolver {
export_map: ExportMap,
export_map2: ExportMap2,
trait_map: TraitMap,
+}
+
+impl Resolver {
/// The main name resolution procedure.
fn resolve(@self, this: @Resolver) {
@@ -105,6 +105,9 @@ struct lookup {
candidate_impls: hashmap<def_id, ()>,
supplied_tps: ~[ty::t],
include_private: bool,
+}
+
+impl lookup {
// Entrypoint:
fn method() -> Option<method_map_entry> {
@@ -158,6 +158,9 @@ struct CoherenceChecker {
// implementations that are defined in the same scope as their base types.
privileged_implementations: hashmap<node_id,()>,
+}
+
+impl CoherenceChecker {
// Create a mapping containing a MethodInfo for every provided
// method in every trait.
@@ -7,9 +7,11 @@ struct cat {
how_hungry : int,
- fn speak() {}
}
+ impl cat {
+ fn speak() {}
+ }
fn cat(in_x : uint, in_y : int) -> cat {
cat {
meows: in_x,
Oops, something went wrong.

0 comments on commit 93d3b8a

Please sign in to comment.