aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorPatrick Walton <[email protected]>2011-03-31 14:37:09 -0700
committerPatrick Walton <[email protected]>2011-03-31 14:37:44 -0700
commit3c1de96cda33e9547adda14dc66294752c99e4c3 (patch)
tree63d8743667358697013299ba452f412f48c658f2 /src/lib
parentMore stuff to go with the new expr_call_self AST node (diff)
downloadrust-3c1de96cda33e9547adda14dc66294752c99e4c3.tar.xz
rust-3c1de96cda33e9547adda14dc66294752c99e4c3.zip
rustc: Use the crate index to look up defs
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ebml.rs21
-rw-r--r--src/lib/io.rs11
2 files changed, 32 insertions, 0 deletions
diff --git a/src/lib/ebml.rs b/src/lib/ebml.rs
index 047218a3..8ed24913 100644
--- a/src/lib/ebml.rs
+++ b/src/lib/ebml.rs
@@ -90,11 +90,32 @@ impure fn move_to_parent(&reader r) {
r.reader.seek(st.tag_pos as int, io.seek_set);
}
+// Moves to the sibling of the current item with the given tag ID.
+impure fn move_to_sibling_with_id(&reader r, uint tag_id) {
+ while (peek(r).id != tag_id) {
+ move_to_next_sibling(r);
+ }
+}
+
+// Moves to the first child of the current item with the given tag ID.
+impure fn move_to_child_with_id(&reader r, uint tag_id) {
+ move_to_first_child(r);
+ move_to_sibling_with_id(r, tag_id);
+}
+
// Reads the data segment of a tag.
impure fn read_data(&reader r) -> vec[u8] {
ret r.reader.read_bytes(bytes_left(r));
}
+// Blows away the tag stack and moves the reader to the given byte position.
+impure fn reset_reader(&reader r, uint pos) {
+ // FIXME: rustc "ty_var in trans.type_of" bug
+ let vec[ebml_state] states = vec();
+ r.states = states;
+ r.reader.seek(pos as int, io.seek_set);
+}
+
impure fn peek(&reader r) -> ebml_tag {
check (bytes_left(r) > 0u);
auto pos = r.reader.tell();
diff --git a/src/lib/io.rs b/src/lib/io.rs
index 11e6408c..7c6c0970 100644
--- a/src/lib/io.rs
+++ b/src/lib/io.rs
@@ -39,6 +39,7 @@ type reader =
impure fn read_c_str() -> str;
impure fn read_le_uint(uint size) -> uint;
impure fn read_le_int(uint size) -> int;
+ impure fn read_be_uint(uint size) -> uint;
impure fn seek(int offset, seek_style whence);
impure fn tell() -> uint; // FIXME: eventually u64
@@ -167,6 +168,16 @@ state obj new_reader(buf_reader rdr) {
}
ret val as int;
}
+ // FIXME deal with eof?
+ impure fn read_be_uint(uint size) -> uint {
+ auto val = 0u;
+ auto sz = size; // FIXME: trans.ml bug workaround
+ while (sz > 0u) {
+ sz -= 1u;
+ val += (read_byte_from_buf_reader(rdr) as uint) << (sz * 8u);
+ }
+ ret val;
+ }
impure fn seek(int offset, seek_style whence) {
ret rdr.seek(offset, whence);
}