about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMarijn Haverbeke <marijnh@gmail.com>2011-04-09 01:56:08 +0200
committerMarijn Haverbeke <marijnh@gmail.com>2011-04-09 01:57:48 +0200
commitc0d0b717ee09d3680ab16fa91b2f5c6af8d40d53 (patch)
treeeb4df8157cb92d1761ff6804097c672ba19de94d
parent129c8392af9711c747df35f2e6b13606bc2a985b (diff)
downloadrust-c0d0b717ee09d3680ab16fa91b2f5c6af8d40d53.tar.gz
rust-c0d0b717ee09d3680ab16fa91b2f5c6af8d40d53.zip
Fix codemap.lookup_pos
Previously, it would place every single location in the first
file of the crate that was parsed.
-rw-r--r--src/comp/front/codemap.rs27
1 files changed, 12 insertions, 15 deletions
diff --git a/src/comp/front/codemap.rs b/src/comp/front/codemap.rs
index 20b4e2eec32..8d18e51b7d9 100644
--- a/src/comp/front/codemap.rs
+++ b/src/comp/front/codemap.rs
@@ -18,10 +18,9 @@ fn new_codemap() -> codemap {
 }
 
 fn new_filemap(str filename, uint start_pos) -> filemap {
-    let vec[uint] lines = vec();
     ret @rec(name=filename,
              start_pos=start_pos,
-             mutable lines=lines);
+             mutable lines=vec(0u));
 }
 
 fn next_line(filemap file, uint pos) {
@@ -29,24 +28,22 @@ fn next_line(filemap file, uint pos) {
 }
 
 fn lookup_pos(codemap map, uint pos) -> loc {
-    for (filemap f in map.files) {
-        if (f.start_pos < pos) {
-            auto line_num = 1u;
-            auto line_start = 0u;
+    auto i = _vec.len[filemap](map.files);
+    while (i > 0u) {
+        i -= 1u;
+        auto f = map.files.(i);
+        if (f.start_pos <= pos) {
             // FIXME this can be a binary search if we need to be faster
-            for (uint line_start_ in f.lines) {
-                // FIXME duplicate code due to lack of working break
-                if (line_start_ > pos) {
+            auto line = _vec.len[uint](f.lines);
+            while (line > 0u) {
+                line -= 1u;
+                auto line_start = f.lines.(line);
+                if (line_start <= pos) {
                     ret rec(filename=f.name,
-                            line=line_num,
+                            line=line + 1u,
                             col=pos-line_start);
                 }
-                line_start = line_start_;
-                line_num += 1u;
             }
-            ret rec(filename=f.name,
-                    line=line_num,
-                    col=pos-line_start);
         }
     }
     log #fmt("Failed to find a location for character %u", pos);