Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add string encoding suffixes #127

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use CharCounter to find line number
  • Loading branch information
Artentus committed Oct 4, 2021
commit 91c712c0e5cbde9e274765677647a0f32d921988
17 changes: 1 addition & 16 deletions src/diagn/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@ use std::rc::Rc;
pub struct Span
{
pub file: Rc<String>,
pub line: Option<usize>,
pub location: Option<(usize, usize)>
}


impl Span
{
pub fn new(filename: Rc<String>, line: usize, start: usize, end: usize) -> Span
pub fn new(filename: Rc<String>, start: usize, end: usize) -> Span
{
Span
{
file: filename,
line: Some(line),
location: Some((start, end))
}
}
Expand All @@ -28,7 +26,6 @@ impl Span
Span
{
file: Rc::new("".to_string()),
line: None,
location: None
}
}
Expand All @@ -46,7 +43,6 @@ impl Span
Span
{
file: self.file.clone(),
line: self.line,
location: Some((start, start))
}
}
Expand All @@ -65,7 +61,6 @@ impl Span
Span
{
file: self.file.clone(),
line: self.line,
location: Some((end, end))
}
}
Expand All @@ -90,19 +85,9 @@ impl Span
Some((start, end))
};

let line = if self.location.unwrap().0 <= other.location.unwrap().0
{
self.line
}
else
{
other.line
};

Span
{
file: self.file.clone(),
line,
location
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ fn drive_inner(
OutputFormat::HexC => binary.format_c_array (16).bytes().collect(),
OutputFormat::LogiSim8 => binary.format_logisim (8) .bytes().collect(),
OutputFormat::LogiSim16 => binary.format_logisim (16).bytes().collect(),
OutputFormat::Debugger => binary.format_debugger() .bytes().collect(),

OutputFormat::AnnotatedHex => binary.format_annotated_hex(fileserver).bytes().collect(),
OutputFormat::AnnotatedBin => binary.format_annotated_bin(fileserver).bytes().collect(),
OutputFormat::Debugger => binary.format_debugger (fileserver).bytes().collect(),
};

if out_stdout
Expand Down
8 changes: 1 addition & 7 deletions src/syntax/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ where S: Into<String>
let filename = Rc::new(src_filename.into());
let mut tokens = Vec::new();
let mut index = 0;
let mut line = 0;
let mut had_error = false;

while index < src.len()
Expand All @@ -258,12 +257,7 @@ where S: Into<String>
check_for_string (&src[index..]).unwrap_or_else(||
(TokenKind::Error, 1)))))));

if kind == TokenKind::LineBreak
{
line += 1;
}

let span = Span::new(filename.clone(), line, index, index + length);
let span = Span::new(filename.clone(), index, index + length);

// Get the source excerpt for variable tokens (e.g. identifiers).
let excerpt = match kind.needs_excerpt()
Expand Down
2 changes: 1 addition & 1 deletion src/test/excerpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn test(src: &str, expected: ExpectedResult<&str>)
let mut fileserver = util::FileServerMock::new();
fileserver.add("test", src_quoted);

let span = diagn::Span::new(Rc::new("test".to_string()), 0, 0, 0);
let span = diagn::Span::new(Rc::new("test".to_string()), 0, 0);

let result = syntax::excerpt_as_string_contents(report.clone(), src_quoted, &span).ok();
let result = result.as_ref().map(|s| s.as_ref());
Expand Down
27 changes: 23 additions & 4 deletions src/util/bitvec_format.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::*;
use crate::util::CharCounter;
use crate::diagn::RcReport;


impl util::BitVec
Expand Down Expand Up @@ -477,7 +479,7 @@ impl util::BitVec
result
}

pub fn format_debugger(&self) -> String
pub fn format_debugger(&self, fileserver: &dyn util::FileServer) -> String
{
let mut result = String::new();

Expand All @@ -489,15 +491,19 @@ impl util::BitVec
{
a.offset.cmp(&b.offset)
});

for span in &sorted_spans
{
let chars = fileserver.get_chars(RcReport::new(), &span.span.file, None).ok().unwrap();
let counter = CharCounter::new(&chars);

addr_width = std::cmp::max(
addr_width,
format!("{:x}", span.addr).len());

if let Some(line) = span.span.line
if let Some((start, _)) = span.span.location
{
let (line, _) = counter.get_line_column_at_index(start);
line_width = std::cmp::max(
line_width,
format!("{}", line).len());
Expand All @@ -513,8 +519,21 @@ impl util::BitVec

for span in &sorted_spans
{
let chars = fileserver.get_chars(RcReport::new(), &span.span.file, None).ok().unwrap();
let counter = CharCounter::new(&chars);

let line = if let Some((start, _)) = span.span.location
{
let (l, _) = counter.get_line_column_at_index(start);
l
}
else
{
0
};

result.push_str(&format!(" {:1$x} | ", span.addr, addr_width));
result.push_str(&format!("{:1$} | ", span.span.line.unwrap_or_default(), line_width));
result.push_str(&format!("{:1$} | ", line, line_width));

if &*span.span.file != prev_filename
{
Expand Down