Added traits to adhere to new coherence requirements

This commit is contained in:
Margaret Meyerhofer 2012-07-18 15:57:22 -07:00
parent 6148309ce1
commit 0551c79ec4
19 changed files with 138 additions and 25 deletions

@ -1 +1 @@
Subproject commit 065a91cf8855489a71b06157d19c1e61888af5b7
Subproject commit c787b5eb2b3cc9ec5be5024098bdc1a368791fb7

@ -1 +1 @@
Subproject commit 678688c3b624761ece89afe45e650158f7ecbc8d
Subproject commit 8e60882ebf2c68766747b1d673a94c77b75f2b78

View file

@ -72,8 +72,12 @@ fn NodeScope() -> NodeScope {
rcu::Scope()
}
trait node_scope {
fn new_node(-k: NodeKind) -> Node;
}
#[warn(no_non_implicitly_copyable_typarams)]
impl NodeScope for NodeScope {
impl NodeScope of node_scope for NodeScope {
fn new_node(-k: NodeKind) -> Node {
self.handle(NodeData({tree: tree::empty(), kind: ~k}))
}

View file

@ -58,7 +58,11 @@ fn Renderer<S: Sink send copy>(sink: S) -> chan<Msg> {
})
}
impl to_float for u8 {
trait to_float {
fn to_float() -> float;
}
impl to_float of to_float for u8 {
fn to_float() -> float {
(self as float) / 255f
}

View file

@ -134,7 +134,11 @@ impl layout_methods for @Box {
// Debugging
impl PrivateNodeMethods for Node {
trait PrivateNodeMethods{
fn dump_indent(ident: uint);
}
impl PrivateNodeMethods of PrivateNodeMethods for Node {
#[doc="Dumps the node tree, for debugging, with indentation."]
fn dump_indent(indent: uint) {
let mut s = ~"";
@ -151,7 +155,11 @@ impl PrivateNodeMethods for Node {
}
}
impl NodeMethods for Node {
trait NodeMethods {
fn dump();
}
impl NodeMethods of NodeMethods for Node {
#[doc="Dumps the subtree rooted at this node, for debugging."]
fn dump() {
self.dump_indent(0u);

View file

@ -6,8 +6,12 @@ import gfx::geometry::au;
import util::tree;
import base::{Box, BlockBox, BTree, layout_methods, BoxTreeReadMethods};
trait block_layout_methods {
fn reflow_block(available_widh: au);
}
#[doc="The public block layout methods."]
impl block_layout_methods for @Box {
impl block_layout_methods of block_layout_methods for @Box {
#[doc="The main reflow routine for block layout."]
fn reflow_block(available_width: au) {
assert self.kind == BlockBox;

View file

@ -146,7 +146,11 @@ impl methods for ctxt {
}
}
impl box_builder_priv for Node {
trait box_builder_priv {
fn determine_box_kind() -> BoxKind;
}
impl box_builder_priv of box_builder_priv for Node {
#[doc="
Determines the kind of box that this node needs. Also, for images, computes the intrinsic
size.
@ -167,7 +171,11 @@ impl box_builder_priv for Node {
}
}
impl box_builder_methods for Node {
trait box_builder_methods {
fn construct_boxes() -> @Box;
}
impl box_builder_methods of box_builder_methods for Node {
#[doc="Creates boxes for this node. This is the entry point."]
fn construct_boxes() -> @Box {
let box_kind = self.determine_box_kind();

View file

@ -8,8 +8,12 @@ import gfx::geometry::au;
import util::tree;
import base::{Box, InlineBox, BTree, layout_methods, BoxTreeReadMethods};
trait inline_layout_methods {
fn reflow_inline(available_width: au);
}
#[doc="The main reflow routine for inline layout."]
impl inline_layout_methods for @Box {
impl inline_layout_methods of inline_layout_methods for @Box {
fn reflow_inline(available_width: au) {
assert self.kind == InlineBox;

View file

@ -6,7 +6,12 @@ import image::base::load;
import base::{Box, BTree, NTree, LayoutData, BoxTreeReadMethods};
import style::style_methods;
impl ApplyStyleBoxMethods for @Box {
trait ApplyStyleBoxMethods {
fn apply_style_for_subtree();
fn apply_style();
}
impl ApplyStyleBoxMethods of ApplyStyleBoxMethods for @Box {
fn apply_style_for_subtree() {
self.apply_style();
for BTree.each_child(self) |child| {

View file

@ -55,7 +55,12 @@ fn attrs_match(attr: Attr, elmt: ElementData) -> bool {
}
}
impl priv_matching_methods for Node {
trait priv_matching_methods {
fn matches_element(sel: ~Selector) -> bool;
fn matches_selector(sel : ~Selector) -> bool;
}
impl priv_matching_methods of priv_matching_methods for Node {
#[doc="
Checks if the given CSS selector, which must describe a single element with no relational
information, describes the given HTML element.
@ -162,7 +167,11 @@ impl priv_matching_methods for Node {
}
}
impl priv_style_methods for Node {
trait priv_style_methods {
fn update_style(decl : StyleDeclaration);
}
impl priv_style_methods of priv_style_methods for Node {
#[doc="Update the computed style of an HTML element with a style specified by CSS."]
fn update_style(decl : StyleDeclaration) {
self.aux(|layout| {
@ -175,7 +184,11 @@ impl priv_style_methods for Node {
}
}
impl matching_methods for Node {
trait matching_methods {
fn match_css_style(styles : Stylesheet);
}
impl matching_methods of matching_methods for Node {
#[doc="Compare an html element to a list of css rules and update its
style according to the rules matching it."]
fn match_css_style(styles : Stylesheet) {

View file

@ -33,7 +33,11 @@ fn default_style_for_node_kind(kind: NodeKind) -> computed_style {
}
}
impl style_priv for Node {
trait style_priv {
fn initialize_style();
}
impl style_priv of style_priv for Node {
#[doc="Set a default auxilliary data so that other threads can modify it.
This is, importantly, the function that creates the layout data for the node (the reader-
@ -50,7 +54,13 @@ impl style_priv for Node {
}
}
impl style_methods for Node {
trait style_methods {
fn initialize_style_for_subtree();
fn get_computed_style() -> computed_style;
fn recompute_style_for_subtree(styles : arc<Stylesheet>);
}
impl style_methods of style_methods for Node {
#[doc="Sequentially initialize the nodes' auxilliary data so they can be updated in parallel."]
fn initialize_style_for_subtree() {
self.initialize_style();

View file

@ -16,8 +16,12 @@ class text_box {
}
}
trait text_layout_methods {
fn reflow_text(_available_width: au, subbox: @text_box);
}
#[doc="The main reflow routine for text layout."]
impl text_layout_methods for @Box {
impl text_layout_methods of text_layout_methods for @Box {
fn reflow_text(_available_width: au, subbox: @text_box) {
alt self.kind {
TextBox(*) { /* ok */ }

View file

@ -16,7 +16,12 @@ import vec::push;
type TokenReader = {stream : port<Token>, mut lookahead : option<Token>};
impl methods for TokenReader {
trait methods {
fn get() -> Token;
fn unget(-tok : Token);
}
impl methods of methods for TokenReader {
fn get() -> Token {
alt copy self.lookahead {
some(tok) { self.lookahead = none; copy tok }

View file

@ -31,7 +31,15 @@ enum Token {
Eof
}
impl css_methods for CssLexer {
trait css_methods {
fn parse_css() -> Token;
fn parse_css_relation(c : u8) -> Token;
fn parse_css_element(c : u8) -> Token;
fn parse_css_attribute(c : u8) -> Token;
fn parse_css_description(c: u8) -> Token;
}
impl css_methods of css_methods for CssLexer {
fn parse_css() -> Token {
let mut ch: u8;
alt self.input_state.get() {

View file

@ -26,7 +26,13 @@ type HtmlLexer = {
mut parser_state: ParseState
};
impl html_methods for HtmlLexer {
trait html_methods {
fn parse_html() -> Token;
fn parse_in_normal_state(c: u8) -> Token;
fn parse_in_tag_state(c: u8) -> Token;
}
impl html_methods of html_methods for HtmlLexer {
fn parse_html() -> Token {
let mut ch: u8;
alt self.input_state.get() {

View file

@ -12,7 +12,13 @@ type InputState = {
reader: io::reader
};
impl u8_methods for u8 {
trait u8_methods {
fn is_whitespace() -> bool;
fn is_alpha() -> bool;
}
impl u8_methods of u8_methods for u8 {
fn is_whitespace() -> bool {
ret self == ' ' as u8 || self == '\n' as u8 || self == '\t' as u8;
}
@ -23,7 +29,17 @@ impl u8_methods for u8 {
}
}
impl util_methods for InputState {
trait util_methods {
fn get() -> CharOrEof;
fn unget(ch: u8);
fn parse_err(err: ~str) -> !;
fn expect(ch: u8);
fn parse_ident() -> ~str;
fn expect_ident(expected: ~str);
fn eat_whitespace();
}
impl util_methods of util_methods for InputState {
fn get() -> CharOrEof {
alt copy self.lookahead {
some(coe) {

View file

@ -182,7 +182,12 @@ fn get_cairo_face(buf: &~[u8]) -> (*cairo_font_face_t, fn@()) {
import azure::cairo_ft;
import cairo_ft::bindgen::cairo_ft_font_face_create_for_ft_face;
impl methods for FT_Error {
trait methods {
fn for_sure();
fn failed() -> bool;
}
impl methods of methods for FT_Error {
fn for_sure() { assert !self.failed() }
fn failed() -> bool { self != 0 as FT_Error }
}

View file

@ -81,7 +81,11 @@ fn create(lib: FT_Library, buf: &~[u8]) -> result<FreeTypeNativeFont, ()> {
})
}
impl methods for FT_Error {
trait methods {
fn succeeded() -> bool;
}
impl methods of methods for FT_Error {
fn succeeded() -> bool { self == 0 as FT_Error }
}

View file

@ -1,4 +1,9 @@
impl methods<T: copy> for *T {
trait methods<T> {
unsafe fn +(idx: uint) -> *T;
unsafe fn [](idx: uint) -> T;
}
impl methods<T: copy> of methods<T> for *T {
unsafe fn +(idx: uint) -> *T {
ptr::offset(self, idx)
}