Eliminate more warnings

This commit is contained in:
Brian Anderson 2012-10-09 14:45:18 -07:00
parent 495946b92b
commit e836269b8d
13 changed files with 73 additions and 72 deletions

View file

@ -142,14 +142,14 @@ impl Content {
}
}
fn handle_msg(msg: Either<ControlMsg,Event>) -> bool {
fn handle_msg(+msg: Either<ControlMsg,Event>) -> bool {
match msg {
Left(control_msg) => self.handle_control_msg(control_msg),
Right(event) => self.handle_event(event)
}
}
fn handle_control_msg(control_msg: ControlMsg) -> bool {
fn handle_control_msg(+control_msg: ControlMsg) -> bool {
match control_msg {
ParseMsg(url) => {
debug!("content: Received url `%s` to parse", url_to_str(copy url));
@ -173,14 +173,14 @@ impl Content {
let document = Document(root, self.scope, css_rules);
let window = Window(self.from_master);
self.relayout(document, &url);
self.relayout(&document, &url);
self.document = Some(@document);
self.window = Some(@window);
self.doc_url = Some(copy url);
let compartment = option::expect(&self.compartment, ~"TODO error checking");
compartment.define_functions(debug_fns);
define_bindings(*compartment,
define_bindings(compartment,
option::get(&self.document),
option::get(&self.window));
@ -202,7 +202,7 @@ impl Content {
//TODO: support extra args. requires passing a *jsval argv
JS_CallFunctionValue(self.cx.ptr, thisValue, timerData.funval,
0, null(), ptr::to_unsafe_ptr(&rval));
self.relayout(*option::get(&self.document), &option::get(&self.doc_url));
self.relayout(self.document.get(), &option::get(&self.doc_url));
return true;
}
@ -249,7 +249,7 @@ impl Content {
join the layout task, and then request a new layout run. It won't wait for the
new layout computation to finish.
*/
fn relayout(document: Document, doc_url: &Url) {
fn relayout(document: &Document, doc_url: &Url) {
debug!("content: performing relayout");
// Now, join the layout so that they will see the latest
@ -266,7 +266,7 @@ impl Content {
}
fn query_layout(query: layout_task::LayoutQuery) -> layout_task::LayoutQueryResponse {
self.relayout(*self.document.get(), &self.doc_url.get());
self.relayout(self.document.get(), &self.doc_url.get());
self.join_layout();
let response_port = Port();
@ -288,7 +288,7 @@ impl Content {
}
Some(document) => {
assert self.doc_url.is_some();
self.relayout(*document, &self.doc_url.get());
self.relayout(document, &self.doc_url.get());
}
}
return true;
@ -301,7 +301,7 @@ impl Content {
}
Some(document) => {
assert self.doc_url.is_some();
self.relayout(*document, &self.doc_url.get());
self.relayout(document, &self.doc_url.get());
}
}
return true;

View file

@ -119,7 +119,7 @@ impl Node : StyleMethods {
fail ~"get_style() called on a node without a style!";
}
// TODO: return a safe reference; don't copy!
return copy *self.aux(|x| copy x).style;
return copy *self.aux(|x| copy *x).style;
}
/**

View file

@ -88,7 +88,7 @@ extern fn finalize(_fop: *JSFreeOp, obj: *JSObject) {
}
}
pub fn init(compartment: bare_compartment, doc: @Document) {
pub fn init(compartment: &bare_compartment, doc: @Document) {
let obj = utils::define_empty_prototype(~"Document", None, compartment);
let attrs = @~[

View file

@ -30,7 +30,7 @@ extern fn finalize(_fop: *JSFreeOp, obj: *JSObject) {
}
}
pub fn init(compartment: bare_compartment) {
pub fn init(compartment: &bare_compartment) {
let obj = utils::define_empty_prototype(~"Element", Some(~"Node"), compartment);
let attrs = @~[
{name: compartment.add_name(~"tagName"),
@ -74,7 +74,7 @@ extern fn HTMLImageElement_getWidth(cx: *JSContext, _argc: c_uint, vp: *mut jsva
let bundle = unwrap(obj);
let node = (*bundle).payload.node;
let scope = (*bundle).payload.scope;
let width = scope.write(node, |nd| {
let width = scope.write(&node, |nd| {
match nd.kind {
~Element(ed) => {
match ed.kind {
@ -105,7 +105,7 @@ extern fn HTMLImageElement_setWidth(cx: *JSContext, _argc: c_uint, vp: *mut jsva
}
let bundle = unwrap(obj);
do (*bundle).payload.scope.write((*bundle).payload.node) |nd| {
do (*bundle).payload.scope.write(&(*bundle).payload.node) |nd| {
match nd.kind {
~Element(ed) => {
match ed.kind {
@ -131,11 +131,11 @@ extern fn getTagName(cx: *JSContext, _argc: c_uint, vp: *mut jsval)
}
let bundle = unwrap(obj);
do (*bundle).payload.scope.write((*bundle).payload.node) |nd| {
do (*bundle).payload.scope.write(&(*bundle).payload.node) |nd| {
match nd.kind {
~Element(ed) => {
let s = str(copy ed.tag_name);
*vp = domstring_to_jsval(cx, s);
*vp = domstring_to_jsval(cx, &s);
}
_ => {
//XXXjdm should probably read the spec to figure out what to do here
@ -148,7 +148,7 @@ extern fn getTagName(cx: *JSContext, _argc: c_uint, vp: *mut jsval)
}
pub fn create(cx: *JSContext, node: Node, scope: NodeScope) -> jsobj unsafe {
let proto = scope.write(node, |nd| {
let proto = scope.write(&node, |nd| {
match nd.kind {
~Element(ed) => {
match ed.kind {

View file

@ -14,7 +14,7 @@ use utils::{rust_box, squirrel_away_unique, get_compartment, domstring_to_jsval,
use libc::c_uint;
use ptr::null;
pub fn init(compartment: bare_compartment) {
pub fn init(compartment: &bare_compartment) {
let obj = utils::define_empty_prototype(~"Node", None, compartment);
let attrs = @~[
@ -42,7 +42,7 @@ pub fn init(compartment: bare_compartment) {
}
pub fn create(cx: *JSContext, node: Node, scope: NodeScope) -> jsobj unsafe {
do scope.write(node) |nd| {
do scope.write(&node) |nd| {
match nd.kind {
~Element(*) => {
element::create(cx, node, scope)
@ -85,7 +85,7 @@ extern fn getFirstChild(cx: *JSContext, _argc: c_uint, vp: *mut jsval) -> JSBool
}
let bundle = unwrap(obj);
do (*bundle).payload.scope.write((*bundle).payload.node) |nd| {
do (*bundle).payload.scope.write(&(*bundle).payload.node) |nd| {
match nd.tree.first_child {
Some(n) => {
let obj = create(cx, n, (*bundle).payload.scope).ptr;
@ -108,7 +108,7 @@ extern fn getNextSibling(cx: *JSContext, _argc: c_uint, vp: *mut jsval) -> JSBoo
}
let bundle = unwrap(obj);
do (*bundle).payload.scope.write((*bundle).payload.node) |nd| {
do (*bundle).payload.scope.write(&(*bundle).payload.node) |nd| {
match nd.tree.next_sibling {
Some(n) => {
let obj = create(cx, n, (*bundle).payload.scope).ptr;

View file

@ -56,8 +56,8 @@ fn jsval_to_str(cx: *JSContext, v: jsval) -> Result<~str, ()> {
}
}
unsafe fn domstring_to_jsval(cx: *JSContext, str: DOMString) -> jsval {
match str {
unsafe fn domstring_to_jsval(cx: *JSContext, str: &DOMString) -> jsval {
match *str {
null_string => {
JSVAL_NULL
}
@ -94,8 +94,8 @@ extern fn has_instance(_cx: *JSContext, obj: **JSObject, v: *jsval, bp: *mut JSB
return 1;
}
pub fn prototype_jsclass(name: ~str) -> fn(+compartment: bare_compartment) -> JSClass {
|+compartment: bare_compartment, copy name| {
pub fn prototype_jsclass(+name: ~str) -> fn(+compartment: bare_compartment) -> JSClass {
|+compartment: bare_compartment| {
{name: compartment.add_name(name),
flags: 0,
addProperty: GetJSClassHookStubPointer(PROPERTY_STUB) as *u8,
@ -122,9 +122,9 @@ pub fn prototype_jsclass(name: ~str) -> fn(+compartment: bare_compartment) -> JS
}
}
pub fn instance_jsclass(name: ~str, finalize: *u8)
pub fn instance_jsclass(+name: ~str, finalize: *u8)
-> fn(+compartment: bare_compartment) -> JSClass {
|+compartment: bare_compartment, copy name| {
|+compartment: bare_compartment| {
{name: compartment.add_name(name),
flags: JSCLASS_HAS_RESERVED_SLOTS(1),
addProperty: GetJSClassHookStubPointer(PROPERTY_STUB) as *u8,
@ -151,7 +151,7 @@ pub fn instance_jsclass(name: ~str, finalize: *u8)
}
}
pub fn define_empty_prototype(name: ~str, proto: Option<~str>, compartment: bare_compartment)
pub fn define_empty_prototype(+name: ~str, +proto: Option<~str>, compartment: &bare_compartment)
-> js::rust::jsobj {
compartment.register_class(utils::prototype_jsclass(name));

View file

@ -64,7 +64,7 @@ extern fn finalize(_fop: *JSFreeOp, obj: *JSObject) {
}
}
pub fn init(compartment: bare_compartment, win: @Window) {
pub fn init(compartment: &bare_compartment, win: @Window) {
let proto = utils::define_empty_prototype(~"Window", None, compartment);
compartment.register_class(utils::instance_jsclass(~"WindowInstance", finalize));

View file

@ -8,7 +8,7 @@ struct Document {
css_rules: ARC<Stylesheet>,
}
fn Document(root: Node, scope: NodeScope, -css_rules: Stylesheet) -> Document {
fn Document(+root: Node, +scope: NodeScope, +css_rules: Stylesheet) -> Document {
Document {
root : root,
scope : scope,

View file

@ -11,24 +11,24 @@ struct ElementData {
}
impl ElementData {
fn get_attr(name: ~str) -> Option<~str> {
let found = do self.attrs.find |attr| { attr.name == name };
fn get_attr(name: &str) -> Option<~str> {
let found = do self.attrs.find |attr| { name == attr.name };
match found {
Some(attr) => Some(copy attr.value),
None => None
}
}
fn set_attr(name: ~str, value: ~str) {
let idx = do self.attrs.position |attr| { attr.name == name };
fn set_attr(name: &str, +value: ~str) {
let idx = do self.attrs.position |attr| { name == attr.name };
match idx {
Some(idx) => self.attrs.set_elt(idx, ~Attr(name, value)),
Some(idx) => self.attrs.set_elt(idx, ~Attr(name.to_str(), value)),
None => {}
}
}
}
fn ElementData(tag_name: ~str, kind: ~ElementKind) -> ElementData {
fn ElementData(+tag_name: ~str, +kind: ~ElementKind) -> ElementData {
ElementData {
tag_name : tag_name,
kind : kind,
@ -41,7 +41,7 @@ struct Attr {
value: ~str,
}
fn Attr(name: ~str, value: ~str) -> Attr {
fn Attr(+name: ~str, +value: ~str) -> Attr {
Attr {
name : name,
value : value,

View file

@ -53,8 +53,8 @@ impl Node {
with a generic implementation of rcu::Handle */
impl Node : cmp::Eq {
pure fn eq(other : &Node) -> bool unsafe {
let my_data : @LayoutData = @self.aux(|a| a);
let ot_data : @LayoutData = @other.aux(|a| a);
let my_data : @LayoutData = @self.aux(|a| *a);
let ot_data : @LayoutData = @other.aux(|a| *a);
core::box::ptr_eq(my_data, ot_data)
}
pure fn ne(other : &Node) -> bool unsafe {
@ -101,8 +101,8 @@ struct DoctypeData {
force_quirks: bool
}
fn DoctypeData(name: ~str, public_id: Option<~str>,
system_id: Option<~str>, force_quirks: bool) -> DoctypeData {
fn DoctypeData(+name: ~str, +public_id: Option<~str>,
+system_id: Option<~str>, force_quirks: bool) -> DoctypeData {
DoctypeData {
name : name,
public_id : public_id,
@ -113,7 +113,7 @@ fn DoctypeData(name: ~str, public_id: Option<~str>,
fn define_bindings(compartment: bare_compartment, doc: @Document,
fn define_bindings(compartment: &bare_compartment, doc: @Document,
win: @Window) {
bindings::window::init(compartment, win);
bindings::document::init(compartment, doc);
@ -141,13 +141,13 @@ fn NodeScope() -> NodeScope {
}
trait NodeScopeExtensions {
fn new_node(-k: NodeKind) -> Node;
fn new_node(+k: NodeKind) -> Node;
}
#[allow(non_implicitly_copyable_typarams)]
impl NodeScope : NodeScopeExtensions {
fn new_node(-k: NodeKind) -> Node {
self.handle(NodeData({tree: tree::empty(), kind: ~k}))
fn new_node(+k: NodeKind) -> Node {
self.handle(&NodeData({tree: tree::empty(), kind: ~k}))
}
}
@ -162,7 +162,7 @@ impl NodeScope : tree::ReadMethods<Node> {
}
fn with_tree_fields<R>(node: &Node, f: fn(&tree::Tree<Node>) -> R) -> R {
self.read(*node, |n| f(&n.tree))
self.read(node, |n| f(&n.tree))
}
}
@ -173,6 +173,6 @@ impl NodeScope : tree::WriteMethods<Node> {
}
fn with_tree_fields<R>(node: &Node, f: fn(&tree::Tree<Node>) -> R) -> R {
self.write(*node, |n| f(&n.tree))
self.write(node, |n| f(&n.tree))
}
}

View file

@ -67,7 +67,7 @@ struct ScopeResource<T:Send,A> {
}
}
fn ScopeResource<T:Send,A>(d : ScopeData<T,A>) -> ScopeResource<T,A> {
fn ScopeResource<T:Send,A>(+d : ScopeData<T,A>) -> ScopeResource<T,A> {
ScopeResource { d: d }
}
@ -99,8 +99,8 @@ impl<T:Send,A> Handle<T,A> {
impl<T:Send,A> Handle<T,A> {
#[doc(str = "Access the reader's view of the handle's data.")]
fn read<U>(f: fn(T) -> U) -> U unsafe {
f(*self.read_ptr())
fn read<U>(f: fn(&T) -> U) -> U unsafe {
f(&*self.read_ptr())
}
#[doc(str = "True if auxiliary data is associated with this handle.")]
@ -117,9 +117,9 @@ impl<T:Send,A> Handle<T,A> {
}
#[doc(str = "access the auxiliary data associated with this handle.")]
fn aux<U>(f: fn(A) -> U) -> U unsafe {
fn aux<U>(f: fn(&A) -> U) -> U unsafe {
assert self.has_aux();
f(*self.read_aux())
f(&*self.read_aux())
}
}
@ -192,29 +192,30 @@ impl<T:Copy Send,A> Scope<T,A> {
self.d.layout_active = false;
}
fn read<U>(h: Handle<T,A>, f: fn(T) -> U) -> U unsafe {
fn read<U>(h: &Handle<T,A>, f: fn(&T) -> U) -> U unsafe {
// Use the write_ptr, which may be more up to date than the read_ptr or may not
f(*h.write_ptr())
f(&*h.write_ptr())
}
fn write<U>(h: Handle<T,A>, f: fn(T) -> U) -> U unsafe {
fn write<U>(h: &Handle<T,A>, f: fn(&T) -> U) -> U unsafe {
let const_read_ptr = ptr::const_offset(h.read_ptr(), 0);
let const_write_ptr = ptr::const_offset(h.write_ptr(), 0);
if self.d.layout_active && const_read_ptr == const_write_ptr {
#debug["marking handle %? as dirty", h];
h.set_write_ptr(cast::reinterpret_cast(&self.clone(h.read_ptr())));
h.set_next_dirty(self.d.first_dirty);
self.d.first_dirty = h;
self.d.first_dirty = *h;
}
f(*h.write_ptr())
f(&*h.write_ptr())
}
// FIXME: This could avoid a deep copy by taking ownership of `v`
#[allow(non_implicitly_copyable_typarams)]
fn handle(v: T) -> Handle<T,A> unsafe {
fn handle(v: &T) -> Handle<T,A> unsafe {
let d: *HandleData<T,A> =
cast::reinterpret_cast(
&libc::malloc(sys::size_of::<HandleData<T,A>>() as size_t));
(*d).read_ptr = self.clone(ptr::to_unsafe_ptr(&v));
(*d).read_ptr = self.clone(ptr::to_unsafe_ptr(v));
(*d).write_ptr = cast::reinterpret_cast(&(*d).read_ptr);
(*d).read_aux = ptr::null();
(*d).next_dirty = null_handle();
@ -242,18 +243,18 @@ mod test {
#[test]
fn handles_get_freed() {
let s: animal_scope = Scope();
s.handle({name:~"henrietta", species:chicken(~{mut eggs_per_day:22u})});
s.handle({name:~"ferdinand", species:bull(~{mut horns:3u})});
s.handle(&{name:~"henrietta", species:chicken(~{mut eggs_per_day:22u})});
s.handle(&{name:~"ferdinand", species:bull(~{mut horns:3u})});
}
fn mutate(a: animal) {
fn mutate(a: &animal) {
match a.species {
chicken(c) => c.eggs_per_day += 1u,
bull(c) => c.horns += 1u
}
}
fn read_characteristic(a: animal) -> uint {
fn read_characteristic(a: &animal) -> uint {
match a.species {
chicken(c) => c.eggs_per_day,
bull(c) => c.horns
@ -264,10 +265,10 @@ mod test {
fn interspersed_execution() {
let s: animal_scope = Scope();
let henrietta =
s.handle({name:~"henrietta",
s.handle(&{name:~"henrietta",
species:chicken(~{mut eggs_per_day:0u})});
let ferdinand =
s.handle({name:~"ferdinand",
s.handle(&{name:~"ferdinand",
species:bull(~{mut horns:0u})});
let iter1 = 3u;
@ -294,9 +295,9 @@ mod test {
for uint::range(0u, iter2) |_i| {
assert hrc == comm::recv(read_port);
s.write(henrietta, mutate);
s.write(&henrietta, mutate);
assert frc == comm::recv(read_port);
s.write(ferdinand, mutate);
s.write(&ferdinand, mutate);
comm::send(wait_chan, ());
}
s.reader_joined();

View file

@ -22,9 +22,9 @@ pub struct Engine<C:Compositor Send Copy> {
content_task: ContentTask
}
pub fn Engine<C:Compositor Send Copy>(compositor: C,
resource_task: ResourceTask,
image_cache_task: ImageCacheTask) -> Engine<C> {
pub fn Engine<C:Compositor Send Copy>(+compositor: C,
+resource_task: ResourceTask,
+image_cache_task: ImageCacheTask) -> Engine<C> {
let render_task = RenderTask(compositor);
let layout_task = LayoutTask(render_task, image_cache_task);
let content_task = ContentTask(layout_task, compositor, resource_task, image_cache_task);
@ -48,7 +48,7 @@ impl<C: Compositor Copy Send> Engine<C> {
}
}
fn handle_request(request: Msg) -> bool {
fn handle_request(+request: Msg) -> bool {
match request {
LoadURLMsg(url) => {
// TODO: change copy to move once we have match move

View file

@ -86,7 +86,7 @@ impl Layout {
match query {
ContentBox(node) => {
// TODO: extract me to a method when I get sibling arms
let response = match node.aux(|a| a).flow {
let response = match node.aux(|a| *a).flow {
None => Err(()),
Some(flow) => {
let start_val : Option<Rect<au>> = None;